1 Reading pictures
2 conversion between drawable and bitmap
2.1 drawable >> Bitmap
The drawable we often refer to is just an abstract class, in which we are actually dealing with derived classes, such as bitmapdrawable (PNG images), gradientdrawable (XML images), and so on. If the given drawable is an instance of bimapdrawable, we can call its Getbitmap method directly, otherwise create a bitmap and draw drawable onto the bitmap.
public static final Bitmap Drawabletobitmap (drawable drawable) {if (Drawa ble instanceof bitmapdrawable) {return ((bitmapdrawable) drawable). Getbitmap (); } else {///according to the creation of a Bitmap with drawable size Bitmap Bitmap = Bitmap.createbitmap (drawabl E.getintrinsicwidth (), Drawable.getintrinsicheight (),//determines the pixel format of the drawable ARGB or RGB, i.e. Is there transparency if there is no transparency, choose rgb_565, save space for storage transparency drawable.getopacity ()! = Pixelformat.opaque? Bitmap.Config.ARGB_8888:Bitmap.Config.RGB_565); Create a canvas with bitmap, draw on canvas is actually draw on the bitmap canvas canvas = new canvas (bitmap); Draw () is actually based on the drawable bounds to determine the drawing position, so set bounds drawable.setbounds (0, 0, drawable.getintrinsicwidth (), drawab Le.getintrinsicheight ()); Draw the drawable on the canvas drawable.draw (canvas); return bitmap; } }
The above code relates to Bitmap.config, which is a detailed introduction to this article:http://www.cnblogs.com/and_he/archive/2012/12/22/ARGB.html
2.2 Bitmap >> drawable
Bitmap can be converted to drawable via bitmapdrawable:
public static final drawable bitmaptodrawable (Bitmap Bitmap) { return new bitmapdrawable (BITMAP);
}
Android image processing