Question

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();
}

No correct solution

OTHER TIPS

I have very little experience with programming, but I randomly found your question with Google.

I think you're getting barcodes because the source image is compressed (like .jpg) so you load compressed data into memory stream and to tiff file, not the pixel data itself.

Maybe try converting your image to uncompressed bitmap file and try over.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top