Data from ImageAnalysis use-case seems to be invalid for Bitmap

60 views
Skip to first unread message

Teodor

unread,
Nov 15, 2022, 10:46:18 AM11/15/22
to Android CameraX Discussion Group
Hi, there,

Long story short... I can't create a Bitmap with the data from the ImageProxy within the analyze method. I get it in format of RGBA_8888. Then I get the buffer, get the byte array and try to decode it into a Bitmap, but unsuccessful.

Is it achievable in this API?

P.S.
Here is a link to me asking in SOF for help.
Thanks in advance for any ideas!

Eino-Ville Talvala

unread,
Nov 15, 2022, 12:24:39 PM11/15/22
to Teodor, Android CameraX Discussion Group
Hi Teodor -

How are you trying to convert the ImageProxy into a Bitmap?  From your wording, I think you might be using BitmapFactory.decodeByteArray or similar.
That method is for decompressing JPEG or PNG files into Bitmap, it's not needed for just converting an RGBA array into a Bitmap.

For that, you probably use createBitmap, though you may need to convert the ImageProxy's ByteArray into an IntArray first, to then get an int[] for that create method.
If you're OK with experimental APIs, you can probably also use Bitmap.wrapHardwareBuffer(ImageProxy.getImage().getHardwareBuffer()).

- Eddy

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/1697e480-46fa-45b5-a6fc-86357fd1c3ben%40android.com.

Teodor

unread,
Nov 16, 2022, 7:38:39 AM11/16/22
to Android CameraX Discussion Group, etal...@google.com, Android CameraX Discussion Group, Teodor
Thanks for the clarification, Eddy,

I wasn't aware of that. It sounds logical, though. I really did end up creating the Bitmap, but it took a while to figure out and set the correct color order (RGBA, ARGB, ABGR...).
I also found out that getting the image in YUV_420 format and converting it instead is actually faster in my case. 😄

Anyways, thanks once again! Got it to work.

Scott Nien

unread,
Nov 18, 2022, 4:29:10 PM11/18/22
to Teodor, Android CameraX Discussion Group, etal...@google.com
> I also found out that getting the image in YUV_420 format and converting it instead is actually faster in my case. 😄

Hi Teodor,  this is amazing.  
Can you share how you convert from YUV_420_888 to the bitmap ?   Maybe we can learn from your discovery. 

Scott

Astha Garg

unread,
Jan 3, 2023, 3:11:52 AM1/3/23
to Android CameraX Discussion Group, scot...@google.com, Android CameraX Discussion Group, etal...@google.com, Teodor
Hi Scott,

I used the below code link to get Bitmap from ImageProxy (In my case imageProxy.getFormat was giving me 35),

for 256 imageProxy.getFormat value,
Reply all
Reply to author
Forward
0 new messages