Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android mutable bitmap

Can someone please explain to me what a mutable bitmap is? What advantages/disadvantages or what limitations do mutable and immutable bitmaps have?

like image 525
Buda Gavril Avatar asked Mar 11 '11 08:03

Buda Gavril


People also ask

How do you make a bitmap mutable?

Options options = new BitmapFactory. Options(); options. inMutable=true; myBitmap=BitmapFactory. decodeFile(filePath,options);

What is an android bitmap?

A bitmap is simply a rectangle of pixels. Each pixel can be set to a given color but exactly what color depends on the type of the pixel. The first two parameters give the width and the height in pixels. The third parameter specifies the type of pixel you want to use.

How do I know if my Android BMP is empty?

You can do a check when you want to return the BitMap look to see if the ArrayList of Paths is bigger than 0 and return the BitMap if so, or else return null.

How do you handle bitmaps in Android as it takes too much memory?

Choose the most appropriate decode method based on your image data source. These methods attempt to allocate memory for the constructed bitmap and therefore can easily result in an OutOfMemory exception. Each type of decode method has additional signatures that let you specify decoding options via the BitmapFactory.


1 Answers

It's about the same difference as with String vs StringBuilder - String is immutable so you can't change its content (well at least not without any hacks), while for StringBuilder you can change its content.

In order to convert an immutable bitmap to a mutable one, check out this post: https://stackoverflow.com/a/16314940/878126.

like image 183
android developer Avatar answered Nov 26 '22 15:11

android developer