@@ -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 ) ) ;
0 commit comments