2

Given a JPEG Encoded byte array taken from a camera, I need to decode it and display its image (bitmap) in my application. From searching around, I've found that there are two primary ways to go about this: use NDK Jpeg Decoding library or use BitmapFactory.decodeByteArray. This is for an experimental embedded device being developed that runs on Android with a built-in camera.

I would greatly prefer to develop the application in SDK not NDK if possible at all, but many people seemed to handle this problem by going straight to NDK, which bugged me a bit.

  • Is there some sort of inherent limitation in BitmapFactory.decodeByteArray that forces you to handle this problem by using libjpeg in NDK (Perhaps speed? Incompatibility?)

Performance isn't a big consideration unless if it takes say more than 45 seconds to decode the image and display it.

This is an important decision I need to make upfront, so I'd appreciate any thoughtful answers. Thank you so much.

Community
  • 1
  • 1
TtT23
  • 6,876
  • 34
  • 103
  • 174
  • The big issue is a memory limitation. [sample post of the problem](http://stackoverflow.com/questions/11820266/android-bitmapfactory-decodestream-out-of-memory-with-a-400kb-file-with-2mb-f) – Fred F Feb 28 '13 at 17:47

1 Answers1

2

Here is a really good example / explanation how you can decode images on device efficiently without using NDK : Displaying Bitmap Efficiently. You have an option to decode bitmap from stream or file so it depends on your needs. But in most of my applications I am using the same method and it's working great. So I suggest you to take a look at the SDK example.

Hope it will helps you.

hardartcore
  • 16,886
  • 12
  • 75
  • 101
  • Thanks for the prompt response. I will always be receiving the image data via JPEG encoded bytes, so as long as there is no known issue with it, I will go ahead and use this method. Although it still seems very strange to me that people opt to go for the NDK method to tackle this problem... – TtT23 Feb 28 '13 at 09:02
  • If you need only to decode stream and show it in your application, there is no need of using NDK, because you can achieve this using Java and Android SDK in a really good way. In my apps I have to decrypt first the image and than decode the decrypted stream and I have never had an issue with that. – hardartcore Feb 28 '13 at 09:05