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 setupFrame(Bitmap bitmap, int width, int color) { if (bitmap.getWidth() <= width * 2 || bitmap.getHeight() <= width * 2) { return bitmap; }/*from www .j ava 2 s . com*/ Bitmap bp = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(bp); canvas.drawBitmap(bitmap, 0, 0, new Paint()); Paint paint = new Paint(); paint.setColor(color); paint.setStrokeWidth(width); paint.setStyle(Style.STROKE); canvas.drawRect(0, 0, canvas.getWidth() - width, canvas.getHeight() - width, paint); bitmap.recycle(); return bp; }
From source file:Main.java
public static Bitmap GetRoundedCornerBitmap(Bitmap bitmap) { try {// w ww . jav a 2 s.c o m Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight())); final float roundPx = 14; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(Color.BLACK); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); final Rect src = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); canvas.drawBitmap(bitmap, src, rect, paint); return output; } catch (Exception e) { return bitmap; } }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) { try {//from w w w . j av a2s . c om Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; } catch (Exception e) { e.printStackTrace(); return bitmap; } }
From source file:Main.java
public static Bitmap drawableToBitmap(Drawable drawable) { if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); }/*from www .j a v a2 s. c om*/ Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Config.ARGB_8888); 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 getRoundedCornerBitmap(Bitmap bitmap) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; 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 = 12; paint.setAntiAlias(true);//from w w w. j ava 2s . c om canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); if (null != bitmap) { bitmap.recycle(); bitmap = null; } return output; }
From source file:Main.java
public static Bitmap roundCorner(Bitmap src, float round) { int width = src.getWidth(); int height = src.getHeight(); Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); canvas.drawARGB(0, 0, 0, 0);//from w w w. ja v a2s . c o m final Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.BLACK); final Rect rect = new Rect(0, 0, width, height); final RectF rectF = new RectF(rect); canvas.drawRoundRect(rectF, round, round, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(src, rect, rect, paint); return result; }
From source file:Main.java
public static Bitmap duplicateBitmap(Bitmap bmpSrc, int width, int height) { if (null == bmpSrc) { return null; }// w w w . j a va2 s . c o m int bmpSrcWidth = bmpSrc.getWidth(); int bmpSrcHeight = bmpSrc.getHeight(); Bitmap bmpDest = Bitmap.createBitmap(width, height, Config.ARGB_8888); if (null != bmpDest) { Canvas canvas = new Canvas(bmpDest); Rect viewRect = new Rect(); final Rect rect = new Rect(0, 0, bmpSrcWidth, bmpSrcHeight); if (bmpSrcWidth <= width && bmpSrcHeight <= height) { viewRect.set(rect); } else if (bmpSrcHeight > height && bmpSrcWidth <= width) { viewRect.set(0, 0, bmpSrcWidth, height); } else if (bmpSrcHeight <= height && bmpSrcWidth > width) { viewRect.set(0, 0, width, bmpSrcWidth); } else if (bmpSrcHeight > height && bmpSrcWidth > width) { viewRect.set(0, 0, width, height); } canvas.drawBitmap(bmpSrc, rect, viewRect, null); } return bmpDest; }
From source file:Main.java
public static Bitmap getRCB(Bitmap bitmap, float roundPX) { // RCB means/*from w ww .j ava 2 s .c o m*/ // Rounded // Corner Bitmap Bitmap dstbmp = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(dstbmp); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPX, roundPX, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return dstbmp; }
From source file:Main.java
/** * @brief Converting picture to bitmap array. * /*from w w w . j a va 2 s. com*/ * @author daiping.zhao * @param bm [IN] bitmap object * * @return Return converted bytes array */ public static Bitmap pictureToBitmap(Picture picture, int width, int height) { Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); Canvas canvas = new Canvas(b); // May need to tweak these values to determine what is the // best scale factor int picWidth = picture.getWidth(); int picHeight = picture.getHeight(); float scaleFactorX = 1.0f; float scaleFactorY = 1.0f; if (picWidth > 0) { scaleFactorX = (float) width / (float) picWidth; } else { return null; } if (picWidth > picHeight) { // If the device is in landscape and the page is shorter // than the height of the view, stretch the thumbnail to fill the // space. scaleFactorY = (float) height / (float) picHeight; } else { // In the portrait case, this looks nice. scaleFactorY = scaleFactorX; } canvas.scale(scaleFactorX, scaleFactorY); picture.draw(canvas); return b; }
From source file:Main.java
public static Bitmap makeCircleBitmap(Bitmap original) { final int width = original.getWidth(); final int height = original.getHeight(); final float radius = Math.min(width, height) / 2; Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Paint paint = new Paint(); paint.setAntiAlias(true);/*from w w w. j a v a 2 s . c o m*/ paint.setShader(new BitmapShader(original, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)); Canvas canvas = new Canvas(bitmap); canvas.drawCircle(radius, radius, radius, paint); original.recycle(); return bitmap; }