[Workspaces] Add encoder parameter to bitmap.save() (#36228)
* [Workspaces] Add encoder parameter to bitmap.save() * 1 more call fixed * Move repeated code to the csharp library
This commit is contained in:
Родитель
f7c9c80ab2
Коммит
a9123bfc23
|
@ -0,0 +1,23 @@
|
|||
// Copyright (c) Microsoft Corporation
|
||||
// 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;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace WorkspacesCsharpLibrary
|
||||
{
|
||||
public class DrawHelper
|
||||
{
|
||||
public static void SaveBitmap(Bitmap bitmap, MemoryStream memory)
|
||||
{
|
||||
ImageCodecInfo imageCodecInfo = ImageCodecInfo.GetImageEncoders().FirstOrDefault(codec => codec.FormatID == ImageFormat.Png.Guid);
|
||||
EncoderParameters encoderParameters = new(1);
|
||||
encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 50);
|
||||
|
||||
bitmap.Save(memory, imageCodecInfo, encoderParameters);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -132,7 +132,7 @@ namespace WorkspacesCsharpLibrary.Models
|
|||
|
||||
using (var memory = new MemoryStream())
|
||||
{
|
||||
previewBitmap.Save(memory, ImageFormat.Png);
|
||||
DrawHelper.SaveBitmap(previewBitmap, memory);
|
||||
memory.Position = 0;
|
||||
|
||||
BitmapImage bitmapImage = new BitmapImage();
|
||||
|
|
|
@ -153,7 +153,8 @@ namespace WorkspacesEditor.Utils
|
|||
}
|
||||
|
||||
using MemoryStream memory = new();
|
||||
previewBitmap.Save(memory, ImageFormat.Png);
|
||||
WorkspacesCsharpLibrary.DrawHelper.SaveBitmap(previewBitmap, memory);
|
||||
|
||||
memory.Position = 0;
|
||||
|
||||
BitmapImage bitmapImage = new();
|
||||
|
@ -311,7 +312,9 @@ namespace WorkspacesEditor.Utils
|
|||
}
|
||||
|
||||
using MemoryStream memory = new();
|
||||
previewBitmap.Save(memory, ImageFormat.Png);
|
||||
|
||||
WorkspacesCsharpLibrary.DrawHelper.SaveBitmap(previewBitmap, memory);
|
||||
|
||||
memory.Position = 0;
|
||||
|
||||
BitmapImage bitmapImage = new();
|
||||
|
|
|
@ -94,7 +94,7 @@ namespace WorkspacesEditor.Utils
|
|||
FileStream fileStream = new FileStream(path, FileMode.CreateNew);
|
||||
using (var memoryStream = new MemoryStream())
|
||||
{
|
||||
icon.Save(memoryStream, ImageFormat.Png);
|
||||
WorkspacesCsharpLibrary.DrawHelper.SaveBitmap(icon, memoryStream);
|
||||
|
||||
BinaryWriter iconWriter = new BinaryWriter(fileStream);
|
||||
if (fileStream != null && iconWriter != null)
|
||||
|
|
Загрузка…
Ссылка в новой задаче