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 loadBitmapFromView(View v, int width, int height) { v.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); v.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY)); v.layout(0, 0, width, height);/*from w w w . j av a 2 s. co m*/ v.draw(c); return b; }
From source file:Main.java
public static Bitmap getRoundedImage(Bitmap bitmap) { Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); BitmapShader shader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP); Paint paint = new Paint(); paint.setShader(shader);//from w w w .j av a 2s.c o m Canvas c = new Canvas(circleBitmap); c.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint); return circleBitmap; }
From source file:Main.java
public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2, float left, float top) { Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig()); Canvas canvas = new Canvas(bmOverlay); canvas.drawBitmap(bmp1, new Matrix(), null); canvas.drawBitmap(bmp2, left, top, null); return bmOverlay; }
From source file:Main.java
public static Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); Bitmap bitmap = Bitmap.createBitmap(width, height, drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, width, height); drawable.draw(canvas);/*from w w w. j av a 2 s . c o m*/ return bitmap; }
From source file:Main.java
public static Bitmap createPngScreenshot2(View view, int thumbnailWidth, int thumbnailHeight, int top) { if (view != null) { Bitmap mCapture;/*from w w w.j av a 2s . c o m*/ try { mCapture = Bitmap.createBitmap(thumbnailWidth, thumbnailHeight, Bitmap.Config.ARGB_8888); } catch (OutOfMemoryError e) { return null; } Canvas c = new Canvas(mCapture); c.drawColor(Color.BLACK); // final int left = view.getScrollX(); // final int top = view.getScrollY(); c.translate(0, -top); //c.scale(0.65f, 0.65f, left, top); try { // draw webview may nullpoint view.draw(c); } catch (Exception e) { } return mCapture; } return null; }
From source file:Main.java
public static Bitmap drawEmptyBackground(int size) { Bitmap bitmap = Bitmap.createBitmap(size, size, Config.RGB_565); Canvas cv = new Canvas(bitmap); Paint background = new Paint(); background.setColor(BACKGROUND_COLOR); cv.drawRect(0, 0, size, size, background); return bitmap; }
From source file:Main.java
/** * Method to create a transparent Bitmap. * * @param w int that represents the width. * @param h int that represents the height. * @return A transparent Bitmap with the specified size. *//*from w w w . j a va 2 s .c o m*/ public static Bitmap createTransparentBitmap(int w, int h) { return Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) { Bitmap bitmap1 = null;/*from w w w. j av a 2 s. co m*/ if (bitmap != null) { bitmap1 = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), android.graphics.Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap1); Paint paint = new Paint(); Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); RectF rectf = new RectF(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(0xffff0000); canvas.drawRoundRect(rectf, 15F, 15F, paint); paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); bitmap.recycle(); } return bitmap1; }
From source file:Main.java
public static Bitmap toOvalBitmap(Bitmap bitmap) { Bitmap output = Bitmap.createBitmap(bitmap.getHeight(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); Paint paint = new Paint(); paint.setAntiAlias(true);/*w w w .ja v a2 s.com*/ Rect rect = new Rect(0, 0, bitmap.getHeight(), bitmap.getHeight()); RectF rectF = new RectF(rect); canvas.drawOval(rectF, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rectF, paint); return output; }
From source file:Main.java
public static Bitmap setGrayscale(Bitmap source) { int width, height; height = source.getHeight();// w w w .j a va 2 s. co m width = source.getWidth(); Bitmap bmpGrayScale = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bmpGrayScale); Paint paint = new Paint(); ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0); ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm); paint.setColorFilter(f); c.drawBitmap(source, 0, 0, paint); return bmpGrayScale; }