-1

I am getting out of memory errors in my android project and it points to this statement:

bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

Is there any alternate way to create a ARGB_8888 bitmap which could save me from out of memory errors?

Suggestions appreciated. Thanks in Advance :)

Shoeb Siddique
  • 2,805
  • 1
  • 22
  • 42
Anyssa K
  • 74
  • 9

1 Answers1

2

There are many problems with memory exceptions with bitmaps on Android, many of which are discussed on stackoverflow. It would probably be best if you went through the existing questions to see if yours matches one of the existing ones, then if not, write up what makes your situation different.

Different Bitmap configurations will have different memory footprints. RGB_565 is a 16 bit colour format. ARGB_8888 is a 32 bit format.

Regardless of which getHolder().setFormat(); configuration you've chosen, or how it's being drawn, an ARGB_8888 Bitmap is going to be significantly larger (in memory) than a Bitmap in RGB_565 format. so Better use RGB_565 format instead of ARGB_8888.

Some examples:

Out of memory exception due to large bitmap size

Android: out of memory exception in Gallery

Android handling out of memory exception on image processing

etc : https://stackoverflow.com/search?q=android+out+of+memory+exception+bitmap

For more detail visit here. android - out of memory exception when creating bitmap

Community
  • 1
  • 1
Harshad
  • 1,344
  • 1
  • 10
  • 25
  • I am trying to create a blank canvas using bitmap with following 2 statements: obBitmapBuffer = Bitmap.createBitmap(obWidth, obHeight, Bitmap.Config.ARGB_8888); obCanvasBuffer = new Canvas(obBitmapBuffer); Can someone please help, how can I do it. (I reffered above mentioned links, but that doesnt ghelps) – Anyssa K Feb 06 '16 at 06:06
  • thanks Harshad, I just tried with RGB_565, it's affecting the animations UI which is not acceptable :( Any other clues? – Anyssa K Feb 06 '16 at 06:26
  • @AnyssaK you can make the Bitmap scale down and then Use it.It will also solve the problem. – Harshad Feb 06 '16 at 06:36