Hi,
I am using BitMiracle LibTIFF. I cannot find any sample code to take a 32bpp argb colour image and write the bitmap to a tiff using this library.
Has anyone else attempted this?
Here is my sample code. It produces a file, but it cannot be viewed by any software that I have.
EDIT: The code now works, but the colors are wrong!
public static void WriteTiff(Image image, string fileName)
{
Bitmap target = image as Bitmap;
BitmapData bmd = target.LockBits(
target.GetRectangle(),
ImageLockMode.ReadOnly,
PixelFormat.Format32bppArgb);
var bits = new byte[bmd.Stride * bmd.Height];
Marshal.Copy(bmd.Scan0, bits, 0, bits.Length);
target.UnlockBits(bmd);
Tiff tiff = Tiff.Open(fileName, "w");
tiff.SetField(TiffTag.IMAGEWIDTH, target.Width);
tiff.SetField(TiffTag.IMAGELENGTH, target.Height);
tiff.SetField(TiffTag.COMPRESSION, Compression.NONE);
tiff.SetField(TiffTag.PHOTOMETRIC, Photometric.RGB);
tiff.SetField(TiffTag.BITSPERSAMPLE, 8);
tiff.SetField(TiffTag.SAMPLESPERPIXEL, 4);
tiff.SetField(TiffTag.ROWSPERSTRIP, target.Height);
tiff.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);
tiff.WriteEncodedStrip(0, bits, bits.Length);
tiff.Close();
}
Thanks