将byte []转换为Image EmguCV,不知道宽度和高度

时间:2017-06-12 16:34:11

标签: java image emgucv

我需要将字节数组(byte[])(来自java BufferedImage)转换为EmguCV Image而不知道宽度和高度。

byte[] bytes = [data];
Image<Gray, byte> image = new Image<Gray, byte>();
image.Bytes = bytes;

你能帮助我吗?

1 个答案:

答案 0 :(得分:0)

I found this [ http://www.emgu.com/forum/viewtopic.php?t=1057 ]

public Image<Bgr, Byte> byteArrayToImage(byte[] byteArrayIn)
{
 MemoryStream ms = new MemoryStream(byteArrayIn);
 Bitmap returnImage = Image.FromStream(ms);

 return new Image<Bgr, byte>(returnImage);
 // you probably need to clean up stuff like the bitmap and the stream...
}

On the emgu forum and retyped it to remove a variable-name typo. Assuming your byte array is a standard image , looks like you can load it into a standard image variable that will automatically figure out sizing. From there you could pass that image to the constructor of your emgu image.