I am trying to compress some png and jpg byte arrays. I am getting a lot of Exceptions trying to save the jpegs back to a byte array. image.ImageDate is a Base64 Byte Array of an image.
relevant c# code:
byte[] newImage;
using (MemoryStream stream = new MemoryStream(image.ImageData))
{
using (RasterImage myImage = (RasterImage) Image.Load(stream))
{
switch (image.MimeType)
{
...
case "image/jpeg":
JpegOptions saveOptions = new JpegOptions
{
BitsPerChannel = 8,
CompressionType = JpegCompressionMode.Progressive,
Quality = 100,
ResolutionSettings = new ResolutionSetting(96.0, 96.0),
ResolutionUnit = ResolutionUnit.Inch,
ColorType = JpegCompressionColorMode.Cmyk,
Palette = ColorPaletteHelper.GetCloseImagePalette(myImage, 256, PaletteMiningMethod.Histogram)
};
using (MemoryStream memory = new MemoryStream())
{
Debug.WriteLine(image.Filename);
try
{
myImage.Save(memory, saveOptions);
}
catch (Exception exception)
{
Debug.WriteLine("Image Byte Array: " + image.ImageData);
}
memory.Position = 0;
newImage = memory.ToArray();
}
break;
...
Sample of Exceptions I am getting from the line myImage.Save(memory, saveOptions):
Exception thrown: ' ' in Aspose.Imaging.dll
Exception thrown: 'Aspose.Imaging.FileFormats.Dng.DngException' in Aspose.Imaging.dll
Exception thrown: ' ' in Aspose.Imaging.dll
Exception thrown: 'Aspose.Imaging.CoreExceptions.ImageSaveException' in Aspose.Imaging.dll
The png file are working fine, its just the jpeg one that are throwing.