
Thread
2008.04.17 14:19 "[Tiff] Writing TIFF Group-4 file from array byte", by Filippo Trimoldi
With Java Morena Framework (an Image Acquisition Framework for Java) I've a
ImageConsumer object that give me a byte Array with size equal to
width*height that I need to write in a Tiff group-4 image with LibTiff
through a JNI. In the C side i perform this code with my byte Array:
// Open the TIFF file
if((image = TIFFOpen(<imagePath> "w")) == NULL)
{
printf("Could not open output.tif for writing\n");
}
TIFFSetField(image, TIFFTAG_ARTIST,"Per ora FILIPPO");
TIFFSetField(image, TIFFTAG_COPYRIGHT,"Per ora è di FILIPPO");
TIFFSetField(image, TIFFTAG_IMAGEWIDTH, *width);
TIFFSetField(image, TIFFTAG_IMAGELENGTH, *height);
TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, 1);
TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, height);
TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4);
TIFFSetField(image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);
TIFFSetField(image, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(image, TIFFTAG_XRESOLUTION, 300.0);
TIFFSetField(image, TIFFTAG_YRESOLUTION, 300.0);
TIFFSetField(image, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
// Write the information to the file
TIFFWriteEncodedStrip(image, 0, <array byte that comes from java>, arraySize);
But the consequent image is wrong. It's seems to be resized on the X axis
but anyway it's wrong.
I noticed that my array that comes from Java it's a simple sequence of 0-1
(probably coming from scanner in this format) of (width*height) lenght.
What i'm doing wrong? Where is my fault?