Skip to content

Commit 97f1d03

Browse files
author
Carl Chang
committed
memory leak checkpoint
1 parent b011848 commit 97f1d03

File tree

12 files changed

+312
-206
lines changed

12 files changed

+312
-206
lines changed

Converters.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Globalization;
34
using System.Windows;
45
using System.Windows.Data;
6+
using System.Windows.Media;
57

68
namespace ZipImageViewer
79
{
@@ -53,6 +55,24 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
5355
}
5456
}
5557

58+
//public class ImageSourceFallbackConverter : IValueConverter
59+
//{
60+
// public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
61+
// switch (value) {
62+
// case List<ImageSource> imgSources:
63+
// if (imgSources.Count > 0) return imgSources[0];
64+
// break;
65+
// }
66+
// return FontAwesome5.ImageAwesome.CreateImageSource(
67+
// FontAwesome5.EFontAwesomeIcon.Solid_Meh,
68+
// new SolidColorBrush(Color.FromArgb(40, 255, 255, 255)));
69+
// }
70+
71+
// public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
72+
// throw new NotImplementedException();
73+
// }
74+
//}
75+
5676
//public class MathAddConverter : IValueConverter
5777
//{
5878
// public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {

Helpers.cs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@ namespace ZipImageViewer
1313
public static class ExtentionMethods
1414
{
1515
public static void AnimateDoubleCubicEase(this UIElement target, DependencyProperty propdp, double toVal, int ms, EasingMode ease,
16-
HandoffBehavior handOff = HandoffBehavior.Compose)
17-
{
18-
var anim = new DoubleAnimation(toVal, new Duration(TimeSpan.FromMilliseconds(ms))) { EasingFunction = new CubicEase { EasingMode = ease } };
19-
target.BeginAnimation(propdp, anim, handOff);
20-
}
21-
public static void AnimateDoubleCubicEase(this Animatable target, DependencyProperty propdp, double toVal, int ms, EasingMode ease,
22-
HandoffBehavior handOff = HandoffBehavior.Compose)
16+
HandoffBehavior handOff = HandoffBehavior.Compose, int begin = 0, EventHandler completed = null)
2317
{
2418
var anim = new DoubleAnimation(toVal, new Duration(TimeSpan.FromMilliseconds(ms))) { EasingFunction = new CubicEase { EasingMode = ease } };
19+
if (begin > 0) anim.BeginTime = TimeSpan.FromMilliseconds(begin);
20+
if (completed != null) anim.Completed += completed;
2521
target.BeginAnimation(propdp, anim, handOff);
2622
}
23+
//public static void AnimateDoubleCubicEase(this Animatable target, DependencyProperty propdp, double toVal, int ms, EasingMode ease,
24+
// HandoffBehavior handOff = HandoffBehavior.Compose, int begin = 0)
25+
//{
26+
// var anim = new DoubleAnimation(toVal, new Duration(TimeSpan.FromMilliseconds(ms))) { EasingFunction = new CubicEase { EasingMode = ease } };
27+
// if (begin > 0) anim.BeginTime = TimeSpan.FromMilliseconds(begin);
28+
// target.BeginAnimation(propdp, anim, handOff);
29+
//}
2730

2831

2932
public static void AnimateBool(this UIElement target, DependencyProperty propdp, bool fromVal, bool toVal, int ms,
@@ -33,13 +36,13 @@ public static void AnimateBool(this UIElement target, DependencyProperty propdp,
3336
anim.KeyFrames.Add(new DiscreteBooleanKeyFrame(toVal, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(ms))));
3437
target.BeginAnimation(propdp, anim, handOff);
3538
}
36-
public static void AnimateBool(this Animatable target, DependencyProperty propdp, bool fromVal, bool toVal, int ms,
37-
HandoffBehavior handOff = HandoffBehavior.Compose) {
38-
var anim = new BooleanAnimationUsingKeyFrames();
39-
if (ms > 0) anim.KeyFrames.Add(new DiscreteBooleanKeyFrame(fromVal, KeyTime.FromTimeSpan(TimeSpan.Zero)));
40-
anim.KeyFrames.Add(new DiscreteBooleanKeyFrame(toVal, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(ms))));
41-
target.BeginAnimation(propdp, anim, handOff);
42-
}
39+
//public static void AnimateBool(this Animatable target, DependencyProperty propdp, bool fromVal, bool toVal, int ms,
40+
// HandoffBehavior handOff = HandoffBehavior.Compose) {
41+
// var anim = new BooleanAnimationUsingKeyFrames();
42+
// if (ms > 0) anim.KeyFrames.Add(new DiscreteBooleanKeyFrame(fromVal, KeyTime.FromTimeSpan(TimeSpan.Zero)));
43+
// anim.KeyFrames.Add(new DiscreteBooleanKeyFrame(toVal, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(ms))));
44+
// target.BeginAnimation(propdp, anim, handOff);
45+
//}
4346

4447

4548
public static double RoundToMultiplesOf(this double input, double multiplesOf) {
@@ -177,7 +180,12 @@ public static BitmapSource GetImageSource(Stream stream, SizeInt decodeSize)
177180
if ((frame.Metadata as BitmapMetadata)?.GetQuery("/app1/ifd/{ushort=274}") is ushort u)
178181
orien = u;
179182
frame = null;
180-
183+
184+
//flip decodeSize according to orientation
185+
if (decodeSize.Width + decodeSize.Height > 0 && orien > 4 && orien < 9)
186+
decodeSize = new SizeInt(decodeSize.Height, decodeSize.Width);
187+
188+
//init bitmapimage
181189
stream.Position = 0;
182190
var bi = new BitmapImage();
183191
bi.BeginInit();
@@ -191,7 +199,7 @@ public static BitmapSource GetImageSource(Stream stream, SizeInt decodeSize)
191199
bi.Freeze();
192200

193201
if (orien < 2) return bi;
194-
202+
//apply orientation based on metadata
195203
var tb = new TransformedBitmap();
196204
tb.BeginInit();
197205
tb.Source = bi;
@@ -208,8 +216,7 @@ public static BitmapSource GetImageSource(Stream stream, SizeInt decodeSize)
208216
case 4:
209217
tb.Transform = new ScaleTransform(1d, -1d);
210218
break;
211-
case 5:
212-
{
219+
case 5: {
213220
var tg = new TransformGroup();
214221
tg.Children.Add(new RotateTransform(90d));
215222
tg.Children.Add(new ScaleTransform(-1d, 1d));
@@ -219,8 +226,7 @@ public static BitmapSource GetImageSource(Stream stream, SizeInt decodeSize)
219226
case 6:
220227
tb.Transform = new RotateTransform(90d);
221228
break;
222-
case 7:
223-
{
229+
case 7: {
224230
var tg = new TransformGroup();
225231
tg.Children.Add(new RotateTransform(90d));
226232
tg.Children.Add(new ScaleTransform(1d, -1d));

MainWindow.xaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
xmlns:fa="http://schemas.fontawesome.com/icons/"
88
mc:Ignorable="d" Background="#FF1F1F1F" UseLayoutRounding="True" Foreground="LightGray"
99
Title="{Binding ElementName=MainWin, Path=CurrentPath}" Height="640" Width="1200" Drop="MainWin_Drop" AllowDrop="True"
10-
Loaded="MainWin_Loaded" PreviewMouseDown="MainWin_MouseDown">
10+
Loaded="MainWin_Loaded" PreviewMouseDown="MainWin_MouseDown" Unloaded="MainWin_Unloaded">
1111
<Window.Resources>
1212
<CollectionViewSource x:Key="ObjectListViewSource" Source="{Binding ElementName=MainWin, Path=ObjectList}">
13-
1413
</CollectionViewSource>
1514
</Window.Resources>
1615
<Grid>
@@ -40,7 +39,7 @@
4039
</Hyperlink>
4140
</TextBlock>
4241
</StackPanel>
43-
<ScrollViewer>
42+
<ScrollViewer x:Name="SV1">
4443
<ItemsControl x:Name="LB1" ItemsSource="{Binding Source={StaticResource ObjectListViewSource}}">
4544
<ItemsControl.ItemsPanel>
4645
<ItemsPanelTemplate>

0 commit comments

Comments
 (0)