[英]How to convert ByteBuffer to Bitmap Image?
I am working on creating an image super-resolution application that uses a TensorFlow Lite model.我正在创建一个使用 TensorFlow Lite 模型的图像超分辨率应用程序。 The model gives the output Image in the form of ByteBuffer and I convert the ByteBuffer to Bitmap.
该模型以 ByteBuffer 的形式给出输出 Image,我将 ByteBuffer 转换为 Bitmap。 Next, I display this Bitmap but nothing shows up.
接下来,我显示此位图,但没有显示任何内容。 The code I am using can be seen below:
我正在使用的代码可以在下面看到:
ByteBuffer out = ByteBuffer.allocate(4 * 384 * 384 * 3);
tflite.run(byteBuffer,out);
byte[] imageBytes= new byte[out.remaining()];
out.get(imageBytes);
final Bitmap outPut_Image = BitmapFactory.decodeByteArray(imageBytes,0,imageBytes.length);
//Toast.makeText(this,tflite.toString(),Toast.LENGTH_LONG).show();
Toast.makeText(this, "Working",Toast.LENGTH_LONG).show();
ImageView imageView = (ImageView) this.findViewById(R.id.imageView2);
imageView.setImageBitmap(outPut_Image);
Please advise me what I am doing wrong here.请告诉我我在这里做错了什么。
BitmapFactory.decodeByteArray() is used for compressed image data such as JPEG. BitmapFactory.decodeByteArray() 用于压缩图像数据,例如 JPEG。
For raw RGB888 data, I think you should convert it to ARGB_8888 format first.对于原始 RGB888 数据,我认为您应该先将其转换为 ARGB_8888 格式。 After that you can use the following snippet to create Bitmap object.
之后,您可以使用以下代码段来创建 Bitmap 对象。
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmap.copyPixelsFromBuffer(buffer);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.