This commit is contained in:
NaBian committed 2021-04-01 21:32:37 +08:00
1 parent 152d3decf3
commit bf26f268bd
1 file changed
+25 -3
@@ -21,6 +21,8 @@ namespace HandyControl.Controls
{ {
private static readonly Guid GifGuid = new Guid("{b96b3caa-0728-11d3-9d7b-0000f81ef32e}"); private static readonly Guid GifGuid = new Guid("{b96b3caa-0728-11d3-9d7b-0000f81ef32e}");
private static readonly Guid GifSingleFrameGuid = new Guid("{b96b3cb0-0728-11d3-9d7b-0000f81ef32e}");
internal IntPtr NativeImage; internal IntPtr NativeImage;
private byte[] _rawData; private byte[] _rawData;
@@ -204,8 +206,12 @@ namespace HandyControl.Controls
streamInfo = Application.GetContentStream(uri) ?? Application.GetResourceStream(uri); streamInfo = Application.GetContentStream(uri) ?? Application.GetResourceStream(uri);
} }
} }
if (streamInfo == null) if (streamInfo == null)
{
throw new FileNotFoundException("Resource not found.", uri.ToString()); throw new FileNotFoundException("Resource not found.", uri.ToString());
}
CreateSourceFromStream(streamInfo.Stream); CreateSourceFromStream(streamInfo.Stream);
} }
catch catch
@@ -214,20 +220,36 @@ namespace HandyControl.Controls
} }
} }
private void SwitchToCommonImage()
{
if (Source == null && Uri != null)
{
SetCurrentValue(SourceProperty, new BitmapImage(Uri));
}
}
[ResourceExposure(ResourceScope.None)] [ResourceExposure(ResourceScope.None)]
[ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)] [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)]
internal static void EnsureSave(GifImage image, string filename, Stream dataStream) internal static void EnsureSave(GifImage image, string filename, Stream dataStream)
{ {
if (!image.RawGuid.Equals(GifGuid)) return; if (!image.RawGuid.Equals(GifGuid) && !image.RawGuid.Equals(GifSingleFrameGuid))
var animatedGif = false; {
image.SwitchToCommonImage();
return;
}
var animatedGif = false;
var dimensions = image.FrameDimensionsList; var dimensions = image.FrameDimensionsList;
if (dimensions.Select(guid => new GifFrameDimension(guid)).Contains(GifFrameDimension.Time)) if (dimensions.Select(guid => new GifFrameDimension(guid)).Contains(GifFrameDimension.Time))
{ {
animatedGif = image.GetFrameCount(GifFrameDimension.Time) > 1; animatedGif = image.GetFrameCount(GifFrameDimension.Time) > 1;
} }
if (!animatedGif) return; if (!animatedGif)
{
image.SwitchToCommonImage();
return;
}
try try
{ {