I am creating images using the Snowbound Library on the fly. I am converting IOCA-AFP images to the PNG format. Is there a way to get the image buffer size for the image to be created? Is there a relationship between the created image size to the inputted IOCA data size?
After the SnowBound Library creates the image, l can get the image size. But I want to allocate memory correctly, so is there a way to get the actual image size before creating the image? If so, how can I determine the buffer size l need?
The Snowbound Library supports numerous formats, each with their own compression and multiple bit depths. This combination of variables makes it a very complex task to predetermine the final file size of an image. A good rule of thumb is typically 3X times the size of the original image size. If this file size is too small, you will get an “Array Out of Bounds Exception Error -38”.
There are several different methods you can use.
1) Use the general rule of thumb by allocating a buffer of 3X times the size of the original image. *Note- IMG_save_bitmap will return the actual size of the written bytes and it can be use to re-adjust the byte array size.
2) Put the IMG_save_bitmap within a loop or a throw statement, where every time the error code -38 is generated, more memory is allocated.
3) Create a temporary file and read back a byte array from it.
*Note: You can only save one page into a TIFF format using IMG_save_bitmap(byte array, format). Creating a temporary file and reading it back in, is the only way to produce a multi-page tiff image in a byte array.