I have an indexed Tiff image which I'm reading using LibTiff.Net to produce a bitmap image of a section of the large image. I believe the Tiff will have 256 colour entries which I want to convert to 256 32-bit pixel values to be used in the output bitmap.
int bitsPerSample = tif.GetField(TiffTag.BITSPERSAMPLE)[0].ToInt();
FieldValue[] colourIndex = tif.GetField(TiffTag.COLORMAP);
int[] palette = new int[256];
for( int i = 0; i < 256; i++ )
{
short red = colourIndex[0].ToShortArray()[i];
short green = colourIndex[1].ToShortArray()[i];
short blue = colourIndex[2].ToShortArray()[i];
palette[i] = ?
}
How do I convert the RGB shorts into a 32-bit pixel value?
Try
System.Drawing.Color.FromArgb(red, green, blue).ToArgb().However, this will only give the right results if LibTiff and Win32 both use the same byte ordering for their ARGB values. It also assumes your red, green, and blue values are in the range 0 to 255; you can scale them if not.