List of usage examples for android.graphics Canvas Canvas
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) public Canvas(long nativeCanvas)
From source file:Main.java
public static Bitmap joinBitmaps(Bitmap first, Bitmap second) { Bitmap result = Bitmap.createBitmap(first.getWidth(), first.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); Paint bitmapPaint = new Paint(); if (second.getWidth() != first.getWidth() && second.getHeight() != first.getHeight()) { second = createScaledToFillBitmap(second, first.getWidth(), first.getHeight()); }//from w ww . ja v a 2s .c om canvas.drawBitmap(first, 0, 0, bitmapPaint); canvas.drawBitmap(second, 0, 0, bitmapPaint); return result; }
From source file:Main.java
public static Bitmap getViewBitmap(View v) { if (v.getWidth() == 0 || v.getHeight() == 0) return null; Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); v.draw(c);/*from ww w . j a va 2s.c om*/ return b; }
From source file:Main.java
public static Bitmap getPaintedBitmap(Bitmap bitmap, Paint paint, boolean deleteOld) { final Bitmap colorBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig()); final Canvas c = new Canvas(colorBitmap); c.drawBitmap(bitmap, 0, 0, paint);/*www .j a va2s . c om*/ if (deleteOld) { bitmap.recycle(); } return colorBitmap; }
From source file:Main.java
public static Bitmap cropBitmap(Bitmap bitmap, Rect rect) { int w = rect.right - rect.left; int h = rect.bottom - rect.top; Bitmap ret = Bitmap.createBitmap(w, h, bitmap.getConfig()); Canvas canvas = new Canvas(ret); canvas.drawBitmap(bitmap, -rect.left, -rect.top, null); bitmap.recycle();/*from w w w .ja va2s. c o m*/ return ret; }
From source file:Main.java
/** * Draws view to a bitmap image./* ww w.jav a 2 s. co 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 createBitmapFrom(Drawable drawable) { Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);/*from www .j a v a 2s .co m*/ Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return bitmap; }
From source file:Main.java
public static Bitmap captureScreen(Activity context) { View cv = context.getWindow().getDecorView(); Bitmap bmp = Bitmap.createBitmap(cv.getWidth(), cv.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(bmp); cv.draw(canvas);/* w ww . j av a 2s . co m*/ return bmp; }
From source file:Main.java
private static byte[] getBitmapBytes(Bitmap bitmap, boolean paramBoolean, int width, int heigth) { Bitmap localBitmap = Bitmap.createBitmap(width, heigth, Bitmap.Config.RGB_565); Canvas localCanvas = new Canvas(localBitmap); int i;//from w w w . j av a 2 s.c om int j; if (bitmap.getHeight() > bitmap.getWidth()) { i = bitmap.getWidth(); j = bitmap.getWidth(); } else { i = bitmap.getHeight(); j = bitmap.getHeight(); } while (true) { localCanvas.drawBitmap(bitmap, new Rect(0, 0, i, j), new Rect(0, 0, width, heigth), null); if (paramBoolean) bitmap.recycle(); ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream(); localBitmap.compress(Bitmap.CompressFormat.JPEG, 100, localByteArrayOutputStream); localBitmap.recycle(); byte[] arrayOfByte = localByteArrayOutputStream.toByteArray(); try { localByteArrayOutputStream.close(); return arrayOfByte; } catch (Exception e) { e.printStackTrace(); } i = bitmap.getHeight(); j = bitmap.getHeight(); } }
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 w w .ja v a 2 s .c o 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 flipAnimation(Bitmap animationTexture, int subImageWidth, int subImageHeight) { Bitmap animationTextureFlipped = Bitmap.createBitmap(animationTexture.getWidth(), animationTexture.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(animationTextureFlipped); Bitmap b;//from ww w . j a v a 2s.c om for (int i = 0; (i + 1) * subImageHeight <= animationTexture.getHeight(); i++) { for (int j = 0; (j + 1) * subImageWidth <= animationTexture.getWidth(); j++) { b = Bitmap.createBitmap(animationTexture, j * subImageWidth, i * subImageHeight, subImageWidth, subImageHeight); b = flip(b); canvas.drawBitmap(b, j * subImageWidth, i * subImageHeight, null); } } return animationTextureFlipped; }