Skip to content

Commit

Permalink
Fix bug in relative URI handling
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaslevesque committed Jul 23, 2018
1 parent 7aa4dce commit 7fc5186
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions WpfAnimatedGif/ImageBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
Expand Down Expand Up @@ -374,7 +375,7 @@ private static void InitAnimationOrImage(Image imageControl)

// For a BitmapImage with a relative UriSource, the loading is deferred until
// BaseUri is set. This method will be called again when BaseUri is set.
bool isLoadingDeferred = IsLoadingDeferred(source);
bool isLoadingDeferred = IsLoadingDeferred(source, imageControl);

if (source != null && shouldAnimate && !isLoadingDeferred)
{
Expand Down Expand Up @@ -426,7 +427,7 @@ private static ObjectAnimationUsingKeyFrames GetAnimation(Image imageControl, Bi
if (animation != null)
return animation;
GifFile gifMetadata;
var decoder = GetDecoder(source, out gifMetadata) as GifBitmapDecoder;
var decoder = GetDecoder(source, imageControl, out gifMetadata) as GifBitmapDecoder;
if (decoder != null && decoder.Frames.Count > 1)
{
var fullSize = GetFullSize(decoder, gifMetadata);
Expand Down Expand Up @@ -519,17 +520,17 @@ private static void TryTwice(Action action)
}
}

private static bool IsLoadingDeferred(BitmapSource source)
private static bool IsLoadingDeferred(BitmapSource source, Image imageControl)
{
var bmp = source as BitmapImage;
if (bmp == null)
return false;
if (bmp.UriSource != null && !bmp.UriSource.IsAbsoluteUri)
return bmp.BaseUri == null;
return bmp.BaseUri == null && (imageControl as IUriContext)?.BaseUri == null;
return false;
}

private static BitmapDecoder GetDecoder(BitmapSource image, out GifFile gifFile)
private static BitmapDecoder GetDecoder(BitmapSource image, Image imageControl, out GifFile gifFile)
{
gifFile = null;
BitmapDecoder decoder = null;
Expand All @@ -548,8 +549,12 @@ private static BitmapDecoder GetDecoder(BitmapSource image, out GifFile gifFile)
else if (bmp.UriSource != null)
{
uri = bmp.UriSource;
if (bmp.BaseUri != null && !uri.IsAbsoluteUri)
uri = new Uri(bmp.BaseUri, uri);
if (!uri.IsAbsoluteUri)
{
var baseUri = bmp.BaseUri ?? (imageControl as IUriContext)?.BaseUri;
if (baseUri != null)
uri = new Uri(baseUri, uri);
}
}
}
else
Expand Down

0 comments on commit 7fc5186

Please sign in to comment.