Here is my question. Bear with me giving a little explanation:
I am reading tiff image into buffer; Each pixel of my tiff is represented by a ushort (16 bits data, non-negtive).
My image size is 64*64 = 4096. When my tiff is loaded into buffer, the buffer length is therefore 8192 (twice as much as 4096). I guess this is because in my buffer, the computer uses 2 bytes to store a single pixel value.
I want to get the value for any particular pixel, in this case should I combine every 2 bytes to 1 ushort?
For example: 00000000 11111111 -> 0000000011111111?
Here is my code:
public static void LoadTIFF(string fileName, int pxlIdx, ref int pxlValue)
{
using (Tiff image = Tiff.Open(fileName, "r"))
{
if (image == null)
return;
FieldValue[] value = image.GetField(TiffTag.IMAGEWIDTH);
int width = value[0].ToInt();
byte[] buffer = new byte[image.StripSize()];
for (int strip = 0; strip < image.NumberOfStrips(); strip++)
image.ReadEncodedStrip(strip, buffer, 0, -1);
// do conversion here:
//ushort bufferHex = BitConverter.ToUInt16(buffer, 0);
image.Close();
}
}
How do I read the byte[] buffer to ensure that I can get the 16 bits ushort pixel value?
Thanks