We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Getting Exceptions Compressing jpegs

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.

@rgordey

In order to investigate the issue further on your end, we need the source files reproducing the issue on your end. I am assuming that you are using the latest version on your end.

Program and Data

@rgordey

I have added a ticket with ID IMAGINGNET-4674 in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.