Home > Software engineering >  Android Media Image to Bitmap Conversion for Tensorflow Lite
Android Media Image to Bitmap Conversion for Tensorflow Lite

Time:04-06

I am taking the camera input and processing it with Tensorflow Lite model to detect the image and gesture. Tensorflow lite model is taking bitmap as an input. I am taking the camera image which is in android media image format. Here my problem is I am trying to convert the media image to bitmap. I have found the following.

  val buffer: ByteBuffer = image!!.planes[0].buffer
        val bytes = ByteArray(buffer.capacity())
        buffer.get(bytes)
        val bmp:Bitmap=BitmapFactory.decodeByteArray(bytes, 0, bytes.size, null)
      

But the converted bitmap is null always. Please guide me in the right way where I am going wrong. Thanks in Advance.

CodePudding user response:

The null return value suggests that the image data could not be decoded when you call BitmapFactory.decodeByteArray. You may check your input contents first.

Here is a link to another similar question about how to convert android.media.image to Bitmap : How to convert android.media.Image to bitmap object?

If it doesn't work, you may also try to check and handle Java error, where this question may be helpful How do I keep track of Java Exceptions

  • Related