Dealing with images in Android is a very common thing, and it's a way to keep track of some of the things you've used to handle picture data.
Switch to bitmap.
The RGB value turns bitmap
Copy Code code as follows:
Private Bitmap Createcolorbitmap (String rgb, int width, int height) {
Bitmap bmp = Bitmap.createbitmap (width, height, Bitmap.Config.ARGB_8888);
int color = Color.parsecolor (RGB);
Bmp.erasecolor (color);
return BMP;
}
Usage
Bitmap bmp = Createcolorbitmap ("#cce8cf", 200, 50);
The color value turns bitmap
Copy Code code as follows:
Private Bitmap createcolorbitmap (int color, int width, int height) {
Bitmap bmp = Bitmap.createbitmap (width, height, Bitmap.Config.ARGB_8888);
Bmp.erasecolor (color);
return BMP;
}
Usage
Bitmap bmp = Createcolorbitmap (Color.Blue, 200, 50);
byte array to bitmap
Copy Code code as follows:
Private Bitmap Getbitmapfrombytearray (byte[] array) {
return Bitmapfactory.decodebytearray (array, 0, array.length);
}
Read files to bitmap
Copy Code code as follows:
Private Bitmap Getbitmapfromfile (String pathName) {
Return Bitmapfactory.decodefile (PathName);
}
Read resources to transfer bitmap
Copy Code code as follows:
Private Bitmap Getbitmapfromresource (resources res, int resid) {
Return Bitmapfactory.decoderesource (res, resid);
}
Input Flow Bitmap
Copy Code code as follows:
Private Bitmap Getbitmapfromstream (InputStream inputstream) {
Return Bitmapfactory.decodestream (InputStream);
}
drawable Turn bitmap
Copy Code code as follows:
Bitmap icon = Bitmapfactory.decoderesource (Context.getresources (), R.drawable.icon_resource);
Switch to drawable.
Resource Transfer drawable
Copy Code code as follows:
drawable drawable = Getresources (). getdrawable (R.drawable.ic_launcher);
Bitmap Turn drawable
Copy Code code as follows:
drawable d = new Bitmapdrawable (Getresources (), bitmap);
Photo Fillet display
By processing the picture data bitmap, the pixels is the radius of the corner.
Copy Code code as follows:
public static Bitmap Getroundedcornerbitmap (Bitmap Bitmap, int pixels) {
Bitmap output = Bitmap.createbitmap (Bitmap.getwidth (), Bitmap
. GetHeight (), config.argb_8888);
Canvas Canvas = new Canvas (output);
final int color = 0xff424242;
Final Paint Paint = new Paint ();
Final Rect Rect = new Rect (0, 0, bitmap.getwidth (), Bitmap.getheight ());
Final RECTF RECTF = new RECTF (rect);
Final float roundpx = pixels;
Paint.setantialias (TRUE);
Canvas.drawargb (0, 0, 0, 0);
Paint.setcolor (color);
Canvas.drawroundrect (RECTF, ROUNDPX, ROUNDPX, paint);
Paint.setxfermode (New Porterduffxfermode (mode.src_in));
Canvas.drawbitmap (Bitmap, rect, rect, paint);
return output;
}