-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 :)

6
  • don't use bitmap, use uri Commented Feb 6, 2016 at 5:26
  • look at this stackoverflow.com/questions/477572/… Commented Feb 6, 2016 at 5:27
  • you can compress the image Commented Feb 6, 2016 at 5:27
  • thank u all, I've gone through these links but couldn't figure out how i can modify this statement (Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)). If I start it this way: BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 8; what should be the statement to create a bitmap Commented Feb 6, 2016 at 5:48
  • @AnyssaK see my updated answer. Commented Feb 6, 2016 at 6:21

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

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)
thanks Harshad, I just tried with RGB_565, it's affecting the animations UI which is not acceptable :( Any other clues?
@AnyssaK you can make the Bitmap scale down and then Use it.It will also solve the problem.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.