Tips For Success

Having the best tools for document imaging is only half of the equation. Our Tech Tips are designed to provide you with valuable information to help you succeed by achieving faster results with our RasterMaster Imaging and Conversion SDKs or VirtualViewer high-speed document and image viewers. New time-saving tips are added monthly - you can receive them through Imaging News or our Tech Tips RSS feed.

Saving out multi-page TIFF files to a byte array in Java

This Tech Tip appeared in Imaging News July 2004.

Saving images to memory on the fly enhances the speed, usability and security of your client-server imaging application by eliminating the necessity of local drive access. Snowbound has expanded this capability in the RasterMaster imaging SDK to allow the saving of multi-page TIFF files to a byte array in Java. Here's an example:

Byte[] saveAs_Tiff_OutputByteArray(String filename)

{

Snowbnd snbd = new Snowbnd();

File input = new File(filename);

int pages = snbd.IMGLOW_get_pages(input.toString());

//Three times the size of the input image

byte imagebytearray[] = new byte[(int)(input.length()*3)];

int outputsize = 0;

for (int pg=0; pg<pages; pg++)

{

//Decompress each page

snbd.IMG_decompress_bitmap(input.toString(),pg);

//Save to tmp

outputsize = snbd.IMG_save_bitmap(imagebytearray,Snow.Defines.TIFF_G4_FAX);

byte array

}

//Correct byte array size

byte imagedata[] = new byte[outputsize];

System.arraycopy(imagebytearray,0,imagedata,0,outputsize);

//corrected data

return imagedata;

}