简体   繁体   中英

Save image as Tiff

I'm getting a byte array from a library and I want to save it as a Tiff file grayscale / 16-bit per pixel.

I'm using this method to do so:

private static void CreateBitmapFromBytes(byte[] pixelValues)
{
  Bitmap pic = new Bitmap(1024, 1024, PixelFormat.Format16bppGrayScale);

  BitmapData picData = pic.LockBits
   ( new Rectangle(0, 0, pic.Width, pic.Height)
   , ImageLockMode.ReadWrite
   , pic.PixelFormat
   );
  IntPtr pixelStartAddress = picData.Scan0;

  Marshal.Copy(pixelValues, 0, pixelStartAddress, pixelValues.Length);

  pic.UnlockBits(picData);
  pic.Save("grid.tif", ImageFormat.Tiff); //< HERE IS THE ERROR
}

And I get the error "A generic error occurred in GDI+". The problem occurs both on Vista/32-bit and Win7/64-bit. I'm using .NET 4.0

EDIT:

If I change ImageFormat.Tiff to ImageFormat.Bmp I don't have the error. But it's still a TIFF image that I want.

PixelFormat.Format16bppGrayScale is unsupported in GDI+. It has nothing to do with TIFF. This format is not yet implemented.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM