Is there a way to change the bit in Bitmap?

cyiwin

Active Member
Licensed User
Longtime User
So bitmaps are big and they take up a lot of RAM. If I understand correctly, on a 1280x720 screen a 16 bit Bitmap uses 1280x720x16 = 14,745,600 bits / 8 = 1,843,200 Bytes or 1.84 MB. A 32 bit bitmap would be double that size.

Sooo...

1) What is the default bit size of Bitmaps in Basic4Android?

2) Is there a way to change the bit size? I have low color images that don't need more than 8 bit...

3) How much RAM is allocated to any given App? My phone has 1GB RAM but it feels like I'm only allowed to use maybe 10MB of it???

Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1) The default configuration is used. Which is ARGB_8888: Bitmap.Config | Android Developers

2) Not with Bitmap object or LoadBitmap / LoadBitmapSample. There are several other "bitmaps" library. You should check them. Note that you will probably get similar result if you use LoadBitmapSample with a size smaller than the screen.

3) It depends on the device. Usually about 32mb. You can ask the OS to give more memory by adding the largeheap attribute.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
To compute the size in memory of a bitmap under Android:
width * height * 4

My Accelerated Surface library provides a few useful tools for bitmaps (ImageUtils class):

LoadScaledBitmap is a better alternative to LoadBitmapSample:
1) It sizes the bitmap exactly to the given dimensions, and not roughly as LoadBitmapSample, so you save memory;
2) It allows you to catch the Out of Memory error (with Try-Catch). So you're free to decide what to do if that happens. There's not an automatic degradation of the image as with LoadBitmapSample.

If your image has no transparent parts, you can use the function ReduceColors to save about 50% of its size.

To know how much memory is available for your app, you can use my Cache library.
 
Upvote 0
Top