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.