[英]How to convert GrayScale image to byte array?
我有灰度图像,但是我想看看它的byte []是否可以执行此操作?
在这里我得到灰度图像;
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)
{
}
如果可以将图像另存为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();
}
}
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.