Differences between Drawable and Bitmap

Source: Internet
Author: User

Bitmap is called a Bitmap. Generally, the format of a Bitmap file is suffixed with bmp. Of course, there are many encoders such as RGB565 and RGB888. As a pixel-by-pixel display object, the execution efficiency is high, but the disadvantage is also obvious low storage efficiency. It is better to understand it as a storage object.
Drawable-as a common image object in Android, it can load images in common formats, such as GIF, PNG, and JPG. Of course, it also supports BMP. Of course, it also provides some advanced visualization objects, such as gradient and graphics.

A bitmap is a Drawable. A Drawable is not necessarily a bitmap. Like all thumbs are fingers but not all fingers are thumbs.
Bitmap is Drawable. Drawable is not necessarily a Bitmap. Just like the thumb is the finger, not all fingers are the same.

The API dictates: API rules:

Though usually not visible to the application, Drawables may take a variety of forms: Although normally invisible to the application, Drawables can take many forms:

Bitmap: the simplest Drawable, a PNG or JPEG image. Bitmap: a simplified Drawable, PNG, or JPEG image.
Nine Patch: an extension to the PNG format allows it to specify information about how to stretch it and place things inside of it.
Shape: contains simple drawing commands instead of a raw bitmap, allowing it to resize better in some cases.
Layers: a compound drawable, which draws multiple underlying drawables on top of each other.
States: a compound drawable that selects one of a set of drawables based on its state.
Levels: a compound drawable that selects one of a set of drawables based on its level.
Scale: a compound drawable with a single child drawable, whose overall size is modified based on the current level.

Summary:

Comparison item display definition occupied memory support scaling support color-difference adjustment support rotation support transparent color rendering speed support pixel operation

If Bitmap is the same, it is slow.
The value of Drawable is the same.

 

Drawable is better than Bitmap in terms of memory usage and drawing speed.

 

1) Drawable and Bitmap can be converted to each other. Drawable occupies much less memory than Bitmap.
(2) setImageDrawable uses a resource file. setImageBitmap uses a bitmap image, which may be read from a local album or converted from a resource file.
(3) public void setImageResource (int resId) occupies the UI thread;

ImageView iv;
String fileName = "/data/com. test/aa.png;
Bitmap bm = BitmapFactory. decodeFile (fileName );
Iv. setImageBitmap (bm); // memory usage, ie:


Bitmap image = BitmapFactory. decodeFile (imgFile. getAbsolutePath ());
ImageView. setImageBitmap (image );


Bitmap image = BitmapFactory. decodeFile (imgFile. getAbsolutePath ());
BitmapDrawable bitmapDrawable = new BitmapDrawable (image );
ImageView. setImageDrawable (bitmapDrawable );

Differences between Drawable and Bitmap

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.