From 7a9aa8d3807ed2ab5f8e494a8a267fb9b20656cb Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Mon, 8 May 2023 00:11:10 +0900 Subject: [PATCH] Catch Exception --- src/Files.App/Helpers/BitmapHelper.cs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Files.App/Helpers/BitmapHelper.cs b/src/Files.App/Helpers/BitmapHelper.cs index 5750b5ef981c..c426f45a0eaf 100644 --- a/src/Files.App/Helpers/BitmapHelper.cs +++ b/src/Files.App/Helpers/BitmapHelper.cs @@ -1,12 +1,9 @@ // Copyright (c) 2023 Files Community // Licensed under the MIT License. See the LICENSE. -using Files.App.Filesystem; using Files.App.Filesystem.StorageItems; using Microsoft.UI.Xaml.Media.Imaging; -using System; using System.IO; -using System.Threading.Tasks; using Windows.Graphics.Imaging; using Windows.Storage; using Windows.Storage.Streams; @@ -22,15 +19,22 @@ public static async Task ToBitmapAsync(this byte[]? data, int decod return null; } - using var ms = new MemoryStream(data); - var image = new BitmapImage(); - if (decodeSize > 0) + try + { + using var ms = new MemoryStream(data); + var image = new BitmapImage(); + if (decodeSize > 0) + { + image.DecodePixelWidth = decodeSize; + image.DecodePixelHeight = decodeSize; + } + await image.SetSourceAsync(ms.AsRandomAccessStream()); + return image; + } + catch (Exception) { - image.DecodePixelWidth = decodeSize; - image.DecodePixelHeight = decodeSize; + return null; } - await image.SetSourceAsync(ms.AsRandomAccessStream()); - return image; } ///