Skip to content

Commit 424b92e

Browse files
committed
Fix: Fixed crash when creating bitmap images (#12303)
1 parent 7a12697 commit 424b92e

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/Files.App/Helpers/BitmapHelper.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using Files.App.Filesystem;
22
using Files.App.Filesystem.StorageItems;
33
using Microsoft.UI.Xaml.Media.Imaging;
4-
using System;
54
using System.IO;
6-
using System.Threading.Tasks;
75
using Windows.Graphics.Imaging;
86
using Windows.Storage;
97
using Windows.Storage.Streams;
@@ -19,15 +17,22 @@ public static async Task<BitmapImage> ToBitmapAsync(this byte[]? data, int decod
1917
return null;
2018
}
2119

22-
using var ms = new MemoryStream(data);
23-
var image = new BitmapImage();
24-
if (decodeSize > 0)
20+
try
21+
{
22+
using var ms = new MemoryStream(data);
23+
var image = new BitmapImage();
24+
if (decodeSize > 0)
25+
{
26+
image.DecodePixelWidth = decodeSize;
27+
image.DecodePixelHeight = decodeSize;
28+
}
29+
await image.SetSourceAsync(ms.AsRandomAccessStream());
30+
return image;
31+
}
32+
catch (Exception)
2533
{
26-
image.DecodePixelWidth = decodeSize;
27-
image.DecodePixelHeight = decodeSize;
34+
return null;
2835
}
29-
await image.SetSourceAsync(ms.AsRandomAccessStream());
30-
return image;
3136
}
3237

3338
/// <summary>

0 commit comments

Comments
 (0)