简体   繁体   English

将 RGB 字节 [][] 图像转换为字节 [] 的最佳方法

[英]Best way to convert RGB byte[][] image to byte[]

Have frame data in the form of a byte[][] object, where each row corresponds to a (R,G,B) channel and is of length (frame width*frame height).以 byte[][] 对象的形式获取帧数据,其中每一行对应一个 (R,G,B) 通道,长度为(帧宽*帧高)。 I wish to convert it to a byte[] format in a similar vein as follows:我希望以类似的方式将其转换为 byte[] 格式,如下所示:

byte[][] original_frame;
byte[] converted_frame = convert(original_frame);
ByteArrayInputStream bis = new ByteArrayInputStream(frame);
BufferedImage bImage2 = ImageIO.read(bis);

From what I can tell, ImageIO assumes a jpeg format.据我所知,ImageIO 采用 jpeg 格式。 Do I need to convert every frame to a JPEG image, or is there a more natural way to do this?我是否需要将每一帧都转换为 JPEG 图像,还是有更自然的方法来做到这一点?

I believe that you are asking how to convert from a 2D array to 1D array.我相信您在问如何从二维数组转换为一维数组。 How to do this if all rows are length 3 is as follows:如果所有行的长度均为 3,如何执行此操作如下:

ArrayList<byte> x = new ArrayList<byte>();
for(int i=0; i<original_frame.length; i++){
   x.add(original_frame[i][0]);
   x.add(original_frame[i][1]);
   x.add(original_frame[i][2]);
}
byte[] converted_frame= new byte[x.size()];
for(int i=0;i<x.size();i++){
   converted_frame[i]=x.get(i);
}

I hope this helps我希望这有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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