Android distinguishes drawable Bitmap Canvas paint_android

Source: Internet
Author: User

1. Conceptual differences:

Many netizens have just started to learn Android platform, the concept of drawable, Bitmap, canvas and paint is not very clear, in fact they are in addition to the drawable in the sun as early as the J2ME has appeared, but in the Android platform, Bitmap, canvas related have changed.

Let's first understand that the display class in the Android platform is view, but it also provides the underlying graphics class Android.graphics, which today are all graphics underlying graphics interfaces.

Bitmap-called a bitmap

General bitmap file format suffix for BMP, of course, there are many encoders such as RGB565, RGB888. As a pixel-by-byte display object, the performance is high, but the disadvantage is very obvious storage efficiency is low. We understand that a storage object is better.

Drawable-As an Android flat-in-common graphics object

It can load commonly used format images, such as GIF, PNG, JPG, of course, also support BMP, of course, also provides some advanced visual objects, such as gradients, graphics and so on.

Canvas-Named Canvas

We can be considered as a process, using various methods to manage bitmap, GL or path paths, while it can coordinate with matrix class to rotate, zoom and other operations, while canvas classes also provide cutting, selection and other operations.

Paint-We can think of it as a drawing tool.

like brushes and brushes. He manages the font, color, and style of each drawing tool.

If you are involved in some Android game development, display effects can be used to efficiently implement your application through these underlying graphic classes.

2. Conversion method:

1) Bitmap converted to byte

Bytearrayoutputstream out = new Bytearrayoutputstream ();
Bitmap.compress (Bitmap.CompressFormat.PNG, out);
Byte[] array= Out.tobytearray ();

2) byte converted to bitmap

Final Contentresolver contentresolver = Context.getcontentresolver ();
Final Packagemanager manager = Context.getpackagemanager ();
Final Cursor C = contentresolver.query (URI, NULL, NULL, NULL, NULL);
Final int icon3dindex = C.getcolumnindexorthrow (ColumnName);
byte[] data = C.getblob (Icon3dindex);
Bitmap Bitmap = bitmapfactory.decodebytearray (data, 0, data.length);

3) Bitmap Conversion drawable

Bitmap Bitmap = new Bitmap (...); drawable drawable = new bitmapdrawable (bitmap);
drawable drawable = new fastbitmapdrawable (bitmap);

4) drawable to Bitmap

A. Bitmapdrawable, fastbitmapdrawable directly with Getbitmap

B. Other types of drawable painted on a bitmap with canvas

Canvas Canvas = new Canvas (bitmap)
  Drawable.draw (Canvas);

This is the difference between the Android drawable Bitmap Canvas Paint, which the Android developer involved in this module can refer to.

Related Article

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.