5

I own a Samsung Galaxy S3, which is capable of capturing pitures of size ~3000 x 2000. And, I am currently developing an application that requires capturing pictures. I use my phone as debugger and I set the best possible size that the device offers for the picture to be captured.

However, if I use this setting, the callback onPictureTaken gives out of memory error at the very first line of it in Bitmap.decodeByteArray method where I try to decode the captured bytes into a bitmap. If I use Bitmap.Options.inSampleSize = 2, there occurs no out of memory error.

I want the application to be able to capture the best that the device offers, and, the device does this in its very own camera application but I can't in mine. I don't understand. How can I overcome this problem?

Blazemonger
  • 90,923
  • 26
  • 142
  • 180
rainbowunicorn
  • 63
  • 1
  • 10
  • Image may be too large to handle. So leaking memory. – Raghunandan Dec 05 '12 at 14:11
  • It probably is, but why can't my application capture pictures that are of the best size that the device can offer. The device iself is capable of capturing images in its own camera application, why can't I in mine? – rainbowunicorn Dec 05 '12 at 14:15
  • please post some code so that community can help you. – Raghunandan Dec 05 '12 at 14:19
  • 1
    There seems to be some misunderstanding here. Android camera captures the image in JPEG format. It uses the resolution you choose in setPictureSize(), and any of supported sizes can be used (check `getSupportedPictureSizes()`. But if you want to convert this JPEG to a bitmap, it's a different matter. The huge bitmap can really blow the heap. Luckily, you rarely need such huge bitmap. We often use decoded bitmap to display the result to the user, so it may be OK to sample to picture down to match the physical screen size. – Alex Cohn Apr 05 '14 at 13:17

2 Answers2

1

http://www.youtube.com/watch?v=_CruQY55HOk. Android custom view Bitmap memory leak. Also have a look at this video. Talks about MAT analyzer which should help. Also recycle bitmaps when not in use

Community
  • 1
  • 1
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
0

An application in android must work with in and around 16mb of memory. if you are going to set the inSampleSize to a very large number to get the image quality as it is, or if u don't perform sampling then it is likely to give u the out of memory exception.

Check out this link and the sample application: Displaying Bitmaps Efficiently

SKK
  • 5,261
  • 3
  • 27
  • 39