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 getWebViewShopshat(WebView webView) { webView.setDrawingCacheEnabled(true); webView.buildDrawingCache();// ww w . j a va 2s. c o m Picture snapShot = webView.capturePicture(); Bitmap bitmap = Bitmap.createBitmap(snapShot.getWidth(), snapShot.getHeight(), Bitmap.Config.ARGB_8888); //bitmap.eraseColor(Color.WHITE); Canvas c = new Canvas(bitmap); int state = c.save(); webView.draw(c); //c.restoreToCount(state); c.restore(); webView.destroyDrawingCache(); return bitmap; }
From source file:Main.java
static private Bitmap smallCoverPostProc(Bitmap smallBitmap) { try {//from w ww . j ava2 s .co m Bitmap smallBitmapPostProc = Bitmap.createBitmap(smallBitmap.getWidth(), smallBitmap.getHeight(), Bitmap.Config.RGB_565); Canvas canvas = new Canvas(); canvas.setBitmap(smallBitmapPostProc); Paint paint = new Paint(); paint.setAntiAlias(true); Bitmap bitmapToShade = Bitmap.createBitmap(smallBitmap, 2, 2, smallBitmap.getWidth() - 4, smallBitmap.getHeight() - 4); BitmapShader bmShader = new BitmapShader(bitmapToShade, TileMode.CLAMP, TileMode.CLAMP); paint.setShader(bmShader); canvas.drawRoundRect(new RectF(2, 2, smallBitmap.getWidth() - 2, smallBitmap.getHeight() - 2), 4, 4, paint); return smallBitmapPostProc; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static Bitmap getRoundedShape(Bitmap scaleBitmapImage, int width) { // TODO Auto-generated method stub int targetWidth = width; int targetHeight = width; Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(targetBitmap); Path path = new Path(); path.addCircle(((float) targetWidth - 1) / 2, ((float) targetHeight - 1) / 2, (Math.min(((float) targetWidth), ((float) targetHeight)) / 2), Path.Direction.CCW); canvas.clipPath(path);//from www . j av a 2s. c om Bitmap sourceBitmap = scaleBitmapImage; canvas.drawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight()), new Rect(0, 0, targetWidth, targetHeight), null); return targetBitmap; }
From source file:Main.java
public static Bitmap takeScreenShot(View view) { if (null == view) { return null; }/*from w w w .java 2 s . c o m*/ assert view.getWidth() > 0 && view.getHeight() > 0; Bitmap.Config config = Bitmap.Config.ARGB_8888; Bitmap bitmap = null; try { bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), config); Canvas canvas = new Canvas(bitmap); view.draw(canvas); } catch (OutOfMemoryError e) { e.printStackTrace(); } return bitmap; }
From source file:Main.java
public static Bitmap GetBitmapClippedCircle(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Path path = new Path(); path.addCircle((float) (width / 2), (float) (height / 2), (float) Math.min(width, (height / 2)), Path.Direction.CCW);//from w w w . ja va2 s . co m Canvas canvas = new Canvas(outputBitmap); canvas.clipPath(path); canvas.drawBitmap(bitmap, 0, 0, null); return outputBitmap; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap srcBitmap, float radius) { Bitmap resultBitmap = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), Bitmap.Config.ARGB_8888);/*from w w w . j av a 2 s . c o m*/ Canvas canvas = new Canvas(resultBitmap); Paint paint = new Paint(); Rect rect = new Rect(0, 0, srcBitmap.getWidth(), srcBitmap.getHeight()); RectF rectF = new RectF(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(0xBDBDBE); canvas.drawRoundRect(rectF, radius, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(srcBitmap, rect, rect, paint); return resultBitmap; }
From source file:Main.java
public static Bitmap toRoundCorner(Bitmap bitmap, int pixels, PorterDuff.Mode mode) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xffffffff; 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);//from ww w.j ava 2 s .co m canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(mode)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:Main.java
/** * Combines multiple bitmaps together into one * @param aParts An array of bitmaps/*from ww w .jav a2 s . c o m*/ * @return Returns a bitmap image */ public static Bitmap combineBitmaps(Bitmap[] aParts) { Bitmap[] parts = aParts; Bitmap result = Bitmap.createBitmap(parts[0].getWidth() * 2, parts[0].getHeight() * 2, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); Paint paint = new Paint(); for (int i = 0; i < parts.length; i++) { canvas.drawBitmap(parts[i], parts[i].getWidth() * (i % 2), parts[i].getHeight() * (i / 2), paint); } return result; }
From source file:Main.java
public static Bitmap getSaturationBitmap(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); Bitmap faceIconGreyBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(faceIconGreyBitmap); Paint paint = new Paint(); ColorMatrix colorMatrix = new ColorMatrix(); colorMatrix.setSaturation(0);// ww w .j av a 2 s . co m ColorMatrixColorFilter colorMatrixFilter = new ColorMatrixColorFilter(colorMatrix); paint.setColorFilter(colorMatrixFilter); canvas.drawBitmap(bitmap, 0, 0, paint); return faceIconGreyBitmap; }
From source file:Main.java
public static final Bitmap grey(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); Bitmap faceIconGreyBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(faceIconGreyBitmap); Paint paint = new Paint(); ColorMatrix colorMatrix = new ColorMatrix(); colorMatrix.setSaturation(0);//from ww w .jav a 2s . com ColorMatrixColorFilter colorMatrixFilter = new ColorMatrixColorFilter(colorMatrix); paint.setColorFilter(colorMatrixFilter); canvas.drawBitmap(bitmap, 0, 0, paint); return faceIconGreyBitmap; }