Fix bug where book with corrupt image cannot be queued.

This commit is contained in:
MBucari 2023-03-11 20:40:02 -07:00
parent 245e55782e
commit 5ec01913d5
11 changed files with 58 additions and 67 deletions

View file

@ -0,0 +1,23 @@
using Dinah.Core.WindowsDesktop.Drawing;
using LibationFileManager;
using System.Drawing;
namespace LibationWinForms
{
internal static class WinFormsUtil
{
private static Bitmap defaultImage;
public static Image TryLoadImageOrDefault(byte[] picture, PictureSize defaultSize = PictureSize.Native)
{
try
{
return ImageReader.ToImage(picture);
}
catch
{
using var ms = new System.IO.MemoryStream(PictureStorage.GetDefaultImage(defaultSize));
return defaultImage ??= new Bitmap(ms);
}
}
}
}