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

Free Support Forum - aspose.com

Memory allocation for image to TIFF conversion

We are implementing an application, that relies on Aspose converting images to TIFF. We have done some testing with a 2GB heap memory allocation, and server ran out of memory during the convertion.

The scenario is the following:

A 200 MPixel PNG image is loaded into an com.aspose.imaging.Image object.
image = Image.load(inputFilestream);

The image is saved to TIFF file using RGB colors and LZW compression:
TiffOptions options = new TiffOptions();
options.setCompression(TiffCompressions.Lzw);
options.setPhotometric(TiffPhotometrics.Rgb);
int[] s = {8, 8, 8};
options.setBitsPerSample(s);
image.save(outputFilename, options);

When doing heap analyzing on dump it seems we get a 32 bytes Aspose imaging Color object allocated for every pixel in the image. Can we use this to calculate an appriximate memory usage for image convertions, if we want to be able to handle up to 200 MPixel images?

Best regards

Hi Jan,

jrp:

When doing heap analyzing on dump it seems we get a 32 bytes Aspose imaging Color object allocated for every pixel in the image. Can we use this to calculate an appriximate memory usage for image convertions, if we want to be able to handle up to 200 MPixel images?

Your above approximation is somehow correct. Reason being, Aspose.Imaging currently stores 4 bytes for color struct and additional bytes for fields required from CLR, therefore each pixel may occupy at least 8 bytes of data. However, for approximation purposes, we would suggest you to use the upper bound, that is 32 bytes for each pixel.

We are currently working to lower the memory utilization by converting the internal structure to use byte array instead of color array. The aforesaid improvements will be published with the release of Aspose.Imaging for .NET 2.6.0. We haven't yet scheduled the said release, although we will inform you as soon as the v2.6.0 is available for public use so you may give it try on your end.