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 addWhiteBorder(Bitmap bmp, int borderSize) { Bitmap bmpWithBorder = Bitmap.createBitmap(bmp.getWidth() + borderSize * 2, bmp.getHeight() + borderSize * 2, bmp.getConfig()); Canvas canvas = new Canvas(bmpWithBorder); canvas.drawColor(Color.WHITE); canvas.drawBitmap(bmp, borderSize, borderSize, null); return bmpWithBorder; }
From source file:Main.java
public static Bitmap combineTwoBitmaps(Bitmap background, Bitmap foreground) { Bitmap combinedBitmap = Bitmap.createBitmap(background.getWidth(), background.getHeight(), background.getConfig());// w w w . java 2 s. c om Canvas canvas = new Canvas(combinedBitmap); Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(background, 0, 0, paint); canvas.drawBitmap(foreground, 0, 0, paint); return combinedBitmap; }
From source file:Main.java
public static Bitmap getDrawableBitmap(Drawable drawable) { Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);//from ww w. ja v a 2 s .c o 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 cutBitmap(Bitmap mBitmap, Rect r, Bitmap.Config config) { int width = r.width(); int height = r.height(); Bitmap croppedImage = Bitmap.createBitmap(width, height, config); Canvas cvs = new Canvas(croppedImage); Rect dr = new Rect(0, 0, width, height); cvs.drawBitmap(mBitmap, r, dr, null); return croppedImage; }
From source file:Main.java
public static Bitmap buildSequence(Context context, String text) { Bitmap myBitmap = Bitmap.createBitmap(160, 84, Bitmap.Config.ARGB_4444); Canvas myCanvas = new Canvas(myBitmap); Paint paint = new Paint(); //Typeface font = Typeface.createFromAsset(context.getAssets(),"fonts/7LED.ttf"); paint.setAntiAlias(true);/*from w w w .j a va 2 s . c o m*/ paint.setSubpixelText(true); //paint.setTypeface(font); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.YELLOW); paint.setTextSize(65); paint.setTextAlign(Paint.Align.CENTER); myCanvas.drawText(text, 80, 60, paint); return myBitmap; }
From source file:Main.java
private static Bitmap toBitmap(Drawable drawable, int width, int height) { Bitmap bmp = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas c = new Canvas(bmp); drawable.setBounds(new Rect(0, 0, width, height)); drawable.draw(c);//w w w . j a v a2 s . c o m return bmp; }
From source file:Main.java
public static Bitmap convertViewToBitmap(View v) { if (v == null) { return null; }/*from w w w. j a va 2 s. co m*/ Bitmap screenshot; screenshot = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888); Canvas c = new Canvas(screenshot); v.draw(c); return screenshot; }
From source file:Main.java
public static Bitmap getBitmapFromView(View v) { if (v == null) { return null; }/*from ww w . ja va 2 s . c o m*/ Bitmap screenShot; screenShot = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888); Canvas mCanvas = new Canvas(screenShot); mCanvas.translate(-v.getScrollX(), -v.getScrollY()); v.draw(mCanvas); return screenShot; }
From source file:Main.java
public static Bitmap highlightSelectedFaceThumbnail(Bitmap originalBitmap) { Bitmap bitmap = originalBitmap.copy(Bitmap.Config.ARGB_8888, true); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setAntiAlias(true);//from w ww .j a va 2 s . com paint.setStyle(Paint.Style.STROKE); paint.setColor(Color.parseColor("#3399FF")); int stokeWidth = Math.max(originalBitmap.getWidth(), originalBitmap.getHeight()) / 10; if (stokeWidth == 0) { stokeWidth = 1; } bitmap.getWidth(); paint.setStrokeWidth(stokeWidth); canvas.drawRect(0, 0, bitmap.getWidth(), bitmap.getHeight(), paint); return bitmap; }
From source file:Main.java
public static Bitmap getScreenshotsForCurrentWindow(Activity activity) { View cv = activity.getWindow().getDecorView(); Bitmap bmp = Bitmap.createBitmap(cv.getWidth(), cv.getHeight(), Bitmap.Config.ARGB_4444); cv.draw(new Canvas(bmp)); return bmp;/*from ww w . java2s . c o m*/ }