[GcodeThumbnails]Return 32 bit ARGB image (#29802)

This commit is contained in:
Pedro Lamas
2023-11-13 16:04:05 +00:00
committed by GitHub
parent ba76bfe04e
commit 22000228e2

View File

@@ -2,6 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using Common.Utilities;
namespace Microsoft.PowerToys.ThumbnailHandler.Gcode
@@ -47,9 +48,20 @@ namespace Microsoft.PowerToys.ThumbnailHandler.Gcode
var gcodeThumbnail = GcodeHelper.GetBestThumbnail(reader);
var thumbnail = gcodeThumbnail?.GetBitmap();
Bitmap thumbnail = null;
if (thumbnail != null && thumbnail.Width != cx && thumbnail.Height != cx)
try
{
thumbnail = gcodeThumbnail?.GetBitmap();
}
catch (Exception)
{
// TODO: add logger
}
if (thumbnail != null && (
((thumbnail.Width != cx || thumbnail.Height > cx) && (thumbnail.Height != cx || thumbnail.Width > cx)) ||
thumbnail.PixelFormat != PixelFormat.Format32bppArgb))
{
// We are not the appropriate size for caller. Resize now while
// respecting the aspect ratio.
@@ -80,7 +92,7 @@ namespace Microsoft.PowerToys.ThumbnailHandler.Gcode
return null;
}
Bitmap destImage = new Bitmap(width, height);
Bitmap destImage = new Bitmap(width, height, PixelFormat.Format32bppArgb);
destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);
@@ -95,6 +107,8 @@ namespace Microsoft.PowerToys.ThumbnailHandler.Gcode
graphics.DrawImage(image, 0, 0, width, height);
}
image.Dispose();
return destImage;
}