List of usage examples for android.graphics Bitmap createBitmap
public static Bitmap createBitmap(int width, int height, @NonNull Config config)
From source file:Main.java
public static Bitmap screenShot(int width, int height, View view) { Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); view.draw(canvas);//from ww w. j a v a 2 s .co m return bitmap; }
From source file:Main.java
public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), (drawable.getOpacity() != PixelFormat.OPAQUE) ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.draw(canvas);/* w w w.ja v a2s . c o m*/ return bitmap; }
From source file:Main.java
public static Bitmap createBitmapFrom(Drawable drawable) { Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);/*from www . j ava 2 s . com*/ Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return bitmap; }
From source file:Main.java
/** * Draws view to a bitmap image./* w ww. ja v a2 s.c o m*/ */ public static Bitmap drawToBitmap(final View viewToDraw) { final Bitmap bitmap = Bitmap.createBitmap(viewToDraw.getWidth(), viewToDraw.getHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); viewToDraw.draw(canvas); return bitmap; }
From source file:Main.java
public static Bitmap bitmapFromDrawable(Drawable drawable) { Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565); Canvas canvas = new Canvas(); canvas.setBitmap(bitmap);// ww w . j a va2 s . c o m drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.draw(canvas); return bitmap; }
From source file:Main.java
public static Bitmap DrawableToBitmap(Drawable drawable) { Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bitmap); //canvas.setBitmap(bitmap); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.draw(canvas);/*w w w . j a va2s. c o m*/ return bitmap; }
From source file:Main.java
static Bitmap createBitmapSafely(int width, int height, Bitmap.Config config, int retryCount) { while (retryCount-- > 0) { try {//from w w w . j a v a 2 s . c om return Bitmap.createBitmap(width, height, config); } catch (OutOfMemoryError e) { e.printStackTrace(); System.gc(); } } return null; }
From source file:Main.java
public static Bitmap drawableToBitmap(Context context, Drawable drawable) { Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);/*from w ww . j a va2 s . co m*/ Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.draw(canvas); return bitmap; }
From source file:Main.java
public static Bitmap toCircleBitmap(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); int r = width < height ? width : height; Bitmap buffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(buffer); Paint paint = new Paint(); paint.setAntiAlias(true);/*from ww w. j a va 2 s.c om*/ RectF rect = new RectF(0, 0, r, r); canvas.drawCircle(r / 2, r / 2, r / 2, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, null, rect, paint); bitmap.recycle(); return buffer; }
From source file:Main.java
public static Bitmap pictureDrawable2Bitmap(PictureDrawable pictureDrawable) { Bitmap bitmap = Bitmap.createBitmap(pictureDrawable.getIntrinsicWidth(), pictureDrawable.getIntrinsicHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.drawPicture(pictureDrawable.getPicture()); return bitmap; }