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

Commit

Permalink
Update Image.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
Awbugl committed Nov 21, 2022
1 parent 866babc commit 9c8f829
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Andreal.Core/UI/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,16 @@ internal static void DrawImage(
int newHeight)
=> g.DrawImage(image.Bitmap, posX, posY, newWidth, newHeight);

private static ImageCodecInfo? _imageCodecInfo;
private static ImageCodecInfo ImageCodecInfo => _imageCodecInfo ??= GetCodecInfo("image/jpeg")!;

private static ImageCodecInfo? GetCodecInfo(string mimeType)
=> ImageCodecInfo.GetImageEncoders().FirstOrDefault(ici => ici.MimeType == mimeType);

public static void SaveAsJpeg(Bitmap bmp, Path path, int quality)
{
var ps = new EncoderParameters(1);
ps.Param[0] = new(Encoder.Quality, quality);
bmp.Save(path, GetCodecInfo("image/jpeg")!, ps);
var ps = new EncoderParameters() { Param = { [0] = new(Encoder.Quality, quality) } };
bmp.Save(path, ImageCodecInfo, ps);
}
}
}

0 comments on commit 9c8f829

Please sign in to comment.