【问题标题】:How to convert GrayScale image to byte array?如何将灰度图像转换为字节数组?
【发布时间】:2014-02-18 15:18:13
【问题描述】:

我有灰度图像,我想看看它的 byte[] 有没有办法做到这一点?

这里我得到了 grayscaleimage ;

 private void OnImage(NGrayscaleImage nImage)
 {
 }

我想把它发送到这个函数;

 private void SendBiometricInfo(byte[] imageBuffer, int imageWidth, int imageHeight)
 {
 }

有没有办法做到这一点?如果是这样,你能帮我处理这个问题吗?

这是我尝试过的......

private void OnImage(NGrayscaleImage nImage)
{
    OnImageByte(ImageToByte(nImage), nImage.Width, nImage.Height);               
    //However here it says there is an invalid arguments.
}


public static byte[] ImageToByte(Image img)
{
    ImageConverter converter = new ImageConverter();
    return (byte[])converter.ConvertTo(img, typeof(byte[]));
}

void OnImageByte(byte[] imgBuffer, int width, int height)
{
}

【问题讨论】:

  • 什么是NGrayscaleImage?您目前尝试的方法有什么问题?
  • 你想看什么?它以 GIF 的形式表示? PNG? BMP?
  • 我可以使用 nImage.Save() 函数,我可以将它保存为 jpg。
  • @musefan 我使用的是 .dll,所以它是一种图像格式。
  • @goGud:我们对此一无所知...当您使用未知课程时,您希望我们如何帮助您?您需要提供有关该课程的更多信息

标签: c# image bytearray


【解决方案1】:

如果您可以将图像保存为 JPG,则推测您的 NGrayscaleImage 继承自 Image,因此您可以尝试将其保存到内存流中

public byte[] imageToByteArray(System.Drawing.Image image)
{
   using (MemoryStream ms = new MemoryStream())
   {
       image.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg);
       return ms.ToArray();
   }
}

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-04
    • 1970-01-01
    • 2014-09-29
    • 1970-01-01
    相关资源
    最近更新 更多