Skip to content

Commit

Permalink
Merge pull request #49 from thomaslevesque/fix-relative-uri-bug
Browse files Browse the repository at this point in the history
Fix bug in relative URI handling
  • Loading branch information
thomaslevesque authored Jul 23, 2018
2 parents 7aa4dce + 6ea02b8 commit 96e12af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
7 changes: 5 additions & 2 deletions WpfAnimatedGif.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2035
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfAnimatedGif", "WpfAnimatedGif\WpfAnimatedGif.csproj", "{D129789C-3096-4D0B-8DD7-FE24A4DF4B21}"
EndProject
Expand Down Expand Up @@ -30,4 +30,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CB8AAAD3-61E6-406F-99AF-21088DDA2A58}
EndGlobalSection
EndGlobal
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 96e12af

Please sign in to comment.