java多線程編程之應用Synchronized症結字同步類辦法。本站提示廣大學習愛好者:(java多線程編程之應用Synchronized症結字同步類辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是java多線程編程之應用Synchronized症結字同步類辦法正文
Android中處置圖象是一件很罕見的工作,這裡記載備忘一些親自應用過的處置圖片數據的辦法。
轉為Bitmap
RGB值轉Bitmap
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);
Color值轉Bitmap
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);
字節數組轉Bitmap
private Bitmap getBitmapFromByteArray(byte[] array) {
return BitmapFactory.decodeByteArray(array, 0, array.length);
}
讀取文件轉Bitmap
private Bitmap getBitmapFromFile(String pathName) {
return BitmapFactory.decodeFile(pathName);
}
讀取資本轉Bitmap
private Bitmap getBitmapFromResource(Resources res, int resId) {
return BitmapFactory.decodeResource(res, resId);
}
輸出流轉Bitmap
private Bitmap getBitmapFromStream(InputStream inputStream) {
return BitmapFactory.decodeStream(inputStream);
}
Drawable轉Bitmap
Bitmap icon = BitmapFactory.decodeResource(context.getResources(),R.drawable.icon_resource);
轉為Drawable
資本轉Drawable
Drawable drawable = getResources().getDrawable(R.drawable.ic_launcher);
Bitmap轉Drawable
Drawable d = new BitmapDrawable(getResources(),bitmap);
圖片圓角展現
經由過程對圖片數據bitmap停止處置便可,個中pixels為邊角的半徑。
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;
}