mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
[GcodePreview]Keep thumbnails transparency (#15575)
* Makes Gcode thumbnails transparent * Don't dispose MemoryStream used in Bitmap Follows up on the remarks shown here: https://docs.microsoft.com/en-us/dotnet/api/system.drawing.bitmap.-ctor?view=dotnet-plat-ext-6.0#system-drawing-bitmap-ctor(system-io-stream)
This commit is contained in:
@@ -106,10 +106,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Gcode
|
||||
{
|
||||
var bitmapBytes = Convert.FromBase64String(bitmapBase64);
|
||||
|
||||
using (var bitmapStream = new MemoryStream(bitmapBytes))
|
||||
{
|
||||
thumbnail = new Bitmap(bitmapStream);
|
||||
}
|
||||
thumbnail = new Bitmap(new MemoryStream(bitmapBytes));
|
||||
}
|
||||
|
||||
return thumbnail;
|
||||
|
||||
@@ -56,10 +56,7 @@ namespace Microsoft.PowerToys.ThumbnailHandler.Gcode
|
||||
{
|
||||
var bitmapBytes = Convert.FromBase64String(bitmapBase64);
|
||||
|
||||
using (var bitmapStream = new MemoryStream(bitmapBytes))
|
||||
{
|
||||
thumbnail = new Bitmap(bitmapStream);
|
||||
}
|
||||
thumbnail = new Bitmap(new MemoryStream(bitmapBytes));
|
||||
|
||||
if (thumbnail.Width != cx && thumbnail.Height != cx)
|
||||
{
|
||||
@@ -137,7 +134,6 @@ namespace Microsoft.PowerToys.ThumbnailHandler.Gcode
|
||||
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
||||
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
|
||||
graphics.Clear(Color.White);
|
||||
graphics.DrawImage(image, 0, 0, width, height);
|
||||
}
|
||||
|
||||
@@ -170,8 +166,8 @@ namespace Microsoft.PowerToys.ThumbnailHandler.Gcode
|
||||
{
|
||||
if (thumbnail != null && thumbnail.Size.Width > 0 && thumbnail.Size.Height > 0)
|
||||
{
|
||||
phbmp = thumbnail.GetHbitmap();
|
||||
pdwAlpha = WTS_ALPHATYPE.WTSAT_RGB;
|
||||
phbmp = thumbnail.GetHbitmap(Color.Transparent);
|
||||
pdwAlpha = WTS_ALPHATYPE.WTSAT_ARGB;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace GcodeThumbnailProviderUnitTests
|
||||
provider.GetThumbnail(256, out IntPtr bitmap, out WTS_ALPHATYPE alphaType);
|
||||
|
||||
Assert.IsTrue(bitmap != IntPtr.Zero);
|
||||
Assert.IsTrue(alphaType == WTS_ALPHATYPE.WTSAT_RGB);
|
||||
Assert.IsTrue(alphaType == WTS_ALPHATYPE.WTSAT_ARGB);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
||||
Reference in New Issue
Block a user