Skip to content
This repository was archived by the owner on Sep 2, 2023. It is now read-only.

Commit 9c8f829

Browse files
author
Awbugl
committed
Update Image.cs
1 parent 866babc commit 9c8f829

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Andreal.Core/UI/Image.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,16 @@ internal static void DrawImage(
121121
int newHeight)
122122
=> g.DrawImage(image.Bitmap, posX, posY, newWidth, newHeight);
123123

124+
private static ImageCodecInfo? _imageCodecInfo;
125+
private static ImageCodecInfo ImageCodecInfo => _imageCodecInfo ??= GetCodecInfo("image/jpeg")!;
126+
124127
private static ImageCodecInfo? GetCodecInfo(string mimeType)
125128
=> ImageCodecInfo.GetImageEncoders().FirstOrDefault(ici => ici.MimeType == mimeType);
126129

127130
public static void SaveAsJpeg(Bitmap bmp, Path path, int quality)
128131
{
129-
var ps = new EncoderParameters(1);
130-
ps.Param[0] = new(Encoder.Quality, quality);
131-
bmp.Save(path, GetCodecInfo("image/jpeg")!, ps);
132+
var ps = new EncoderParameters() { Param = { [0] = new(Encoder.Quality, quality) } };
133+
bmp.Save(path, ImageCodecInfo, ps);
132134
}
133135
}
134136
}

0 commit comments

Comments
 (0)