1. Concept difference:
Many netizens have just started learning the Android platform, and they are not very clear about the concepts between Drawable, Bitmap, Canvas and Paint. In fact, in addition to Drawable, they have appeared in Sun's J2ME, but in the Android platform, Bitmap and Canvas related changes.
First, let us understand that the display class in the Android platform is a View, but also provides the underlying graphics class. What we are talking about today is the graphics underlying graphics interface.
Bitmap - called bitmap
The file format of the general bitmap is suffixed with bmp, and 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 disadvantages are also obvious that the storage efficiency is low. We understand that it is better to store objects.
Drawable - As a common graphic object under Android flat
It can load images in commonly used formats, such as GIF, PNG, and JPG. Of course, it also supports BMP. Of course, it also provides some advanced visual objects, such as gradients, graphics, etc.
Canvas - named Canvas
We can see it as a processing process, using various methods to manage Bitmap, GL or Path paths. At the same time, it can cooperate with the Matrix matrix class to perform rotation, scaling and other operations on the image. At the same time, the Canvas class also provides cropping, selection and other operations.
Paint - We can think of it as a drawing tool
For example, brushes and brushes. He manages the font, color, and style of each drawing tool.
If you involve some Android game development and display special effects, you can use these underlying graphics classes to efficiently implement your own applications.
2. Conversion method:
1) Bitmap is converted to byte
ByteArrayOutputStream out = new ByteArrayOutputStream(); (, 100, out); byte[] array= ();
2) Convert byte to bitmap
final ContentResolver contentResolver = (); final PackageManager manager = (); final Cursor c = (uri, null, null, null, null); final int icon3DIndex = (ColumnName); byte[] data = (icon3DIndex); Bitmap bitmap = (data, 0, );
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 use getBitmap
b. Other types of Drawables are drawn on a bitmap with Canvas
Canvas canvas = new Canvas(bitmap) (canvas); Drawable d = (0); Bitmap bitmap = ((BitmapDrawable)d).getBitmap();
The above is the difference between Drawable Bitmap Canvas Paint in Android. Android developers who are involved in this module can refer to it.