将图像另存为抖音

本文关键字:另存为 图像 | 更新日期: 2023-09-27 18:26:47

我正在从库中获取一个字节数组,我想将其保存为Tiff文件灰度/16位/像素。

我使用这种方法来做到这一点:

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
}

我得到了错误"GDI+中发生了一个通用错误"。此问题同时出现在Vista/32位和Win7/64位上。我正在使用.NET 4.0

编辑:

如果我将ImageFormat.Tiff更改为ImageFormat.Bmp,则不会出现错误。但它仍然是我想要的TIFF图像。

将图像另存为抖音

以下是解决您的问题的解决方案正在解决"GDI+中发生一般错误"异常。

PixelFormat.Format16bppGrayScale在GDI+中不受支持。它与TIFF无关。此格式尚未实现。