| AWARE [SYSTEMS] | Imaging expertise for the Delphi developer | |||||||
![]() |
TIFF and LibTiff Mailing List Archive | |||||||
LibTiff Mailing List
TIFF and LibTiff Mailing List Archive Contact
The TIFF Mailing List Homepage |
Thread2009.07.16 14:33 "reading an 8 bit image", by Joe TracyHi,
I have been reading 16 bit grayscale tiff images for a while now using
the ReadScanLine method: this works fine.
However, I am unable to figure out how to read in an 8 bit image. I
have tried many variations, but the closest I come is this:
(I am just putting the pixel data into an array, then subsequently
create an image later. Using this method, my image is not correct.)
I am using C#.Net, using DLLImports for the libtiff calls.
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, ref w);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, ref h);
TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, ref
bits);
TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, ref
samples);
pixel_array = new int[h, w, 3];
UInt32 size = h * w;
byte* raster = _TIFFmalloc((UInt32)(size *
sizeof(UInt32)));
int val = TIFFReadRGBAImage(tif, w, h,
(byte*)raster, 0);
if (val != 0)
{
for (int j = 0; j < h; j++)
{
for (int i = 0, ptr = 0; i < w; i++,
ptr += 3)
{
pixel_array[j, i, 0] =
(int)raster[ptr + j * w];
pixel_array[j, i, 1] =
(int)raster[ptr + 1 + j * w];
pixel_array[j, i, 2] =
(int)raster[ptr + 2 + j * w];
}
}
}
_TIFFfree((byte*)raster);
My image comes in "garbled". It is close, but not there.
Any help is appreciated.
Thanks,
Joe
|
|||||||