I would like to copy the pixels of the image from imagebox to a TIFF file. I want to use TIFF tags as well so i'm using LibTiff.Net.
I thought that first I use copy the image from imagebox to MemoryStream and then copy memory stream into byte array and in the end just write out the bytes from byte array into the TIFF file. But i dont know how to do it.
I went through all the proccess, but the only thing i get in the file is like some "barcodes". Oh, and I would need the output file in 32 bit floating point.
Here is where i get so far:
Tiff output = Tiff.Open(filename, "w");
if (output == null)
{
return;
}
else
{
MemoryStream ms = new MemoryStream();
this.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Tiff);
byte[] buff = ms.GetBuffer();
output.SetField(TiffTag.IMAGEWIDTH, width);
output.SetField(TiffTag.IMAGELENGTH, height);
output.SetField(TiffTag.SAMPLESPERPIXEL, 1);
output.SetField(TiffTag.BITSPERSAMPLE, 32);
output.SetField(TiffTag.SAMPLEFORMAT, 3);
output.SetField(TiffTag.ORIENTATION, BitMiracle.LibTiff.Classic.Orientation.TOPLEFT);
output.SetField(TiffTag.ROWSPERSTRIP, height);
output.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);
output.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISBLACK);
output.SetField(TiffTag.COMPRESSION, Compression.NONE);
output.SetField(TiffTag.FILLORDER, FillOrder.MSB2LSB);
for (int i = 0; i < height; ++i)
output.WriteScanline(buff, i);
ms.Close();
output.Close();
}