GetJpeg() now fails with same exception message as GetSize()

This commit is contained in:
Syping 2025-11-23 05:49:38 +01:00
parent 63bee738b2
commit 5395f8ee2e

37
Jpeg.cs
View file

@ -30,23 +30,28 @@ internal class Jpeg {
}
internal static Byte[] GetJpeg(Stream input, bool imageAsIs, out Size size) {
if (!imageAsIs) {
using Image image = Image.Load(input);
size = image.Size;
image.Metadata.ExifProfile = null;
using MemoryStream jpegStream = new();
image.SaveAsJpeg(jpegStream, new() {
Quality = 100,
ColorType = JpegEncodingColor.YCbCrRatio444
});
return jpegStream.ToArray();
try {
if (imageAsIs) {
using MemoryStream jpegStream = new();
input.CopyTo(jpegStream);
Byte[] jpeg = jpegStream.ToArray();
size = GetSize(jpeg);
return jpeg;
}
else {
using Image image = Image.Load(input);
size = image.Size;
image.Metadata.ExifProfile = null;
using MemoryStream jpegStream = new();
image.SaveAsJpeg(jpegStream, new() {
Quality = 100,
ColorType = JpegEncodingColor.YCbCrRatio444
});
return jpegStream.ToArray();
}
}
else {
using MemoryStream jpegStream = new();
input.CopyTo(jpegStream);
Byte[] jpeg = jpegStream.ToArray();
size = GetSize(jpeg);
return jpeg;
catch (UnknownImageFormatException exception) {
throw new Exception("Unsupported Image Format", exception);
}
}