Java 如何将ByteBuffer转换为位图图像?
我正在创建一个使用TensorFlow Lite模型的图像超分辨率应用程序。该模型以ByteBuffer的形式给出输出图像,我将ByteBuffer转换为位图。接下来,我显示这个位图,但什么也没有显示。我使用的代码如下所示:Java 如何将ByteBuffer转换为位图图像?,java,android,tensorflow,tensorflow-lite,Java,Android,Tensorflow,Tensorflow Lite,我正在创建一个使用TensorFlow Lite模型的图像超分辨率应用程序。该模型以ByteBuffer的形式给出输出图像,我将ByteBuffer转换为位图。接下来,我显示这个位图,但什么也没有显示。我使用的代码如下所示: ByteBuffer out = ByteBuffer.allocate(4 * 384 * 384 * 3); tflite.run(byteBuffer,out); byte[] imageByt
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);
请告诉我我做错了什么。BitmapFactory.decodeByteArray()用于压缩图像数据,如JPEG 对于原始RGB888数据,我认为应该首先将其转换为ARGB_8888格式。 之后,可以使用以下代码段创建位图对象
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmap.copyPixelsFromBuffer(buffer);
Toast.makeText(这个“工作”,Toast.LENGTH_LONG.show()代码>???工作你什么也没查<代码>如果(outPut_Image==null){toast位图将变得太大,无法使用可用内存并返回}
。toast只是检查try块是否正常工作。好吧。。。位图是否为空?你为什么不作出反应?有什么解决办法吗?