Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Fixed crash when creating bitmap images #12303

Merged
merged 1 commit into from
May 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/Files.App/Helpers/BitmapHelper.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,15 +19,22 @@ public static async Task<BitmapImage> 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;
}

/// <summary>
Expand Down