List of usage examples for android.graphics Rect Rect
public Rect(int left, int top, int right, int bottom)
From source file:Main.java
public static Bitmap getCircleBitmap(Bitmap bitmap, boolean recycleable) { final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(output); final int color = Color.RED; 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);//from w w w . ja v a 2 s . c o m canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawOval(rectF, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); if (recycleable) { bitmap.recycle(); } return output; }
From source file:Main.java
public static Bitmap circleBitmap(Bitmap source, boolean recycle) { if (source == null) { return null; }/*ww w . j ava 2 s. c o m*/ // Create custom bitmap Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); // Compute sizes final int color = Color.RED; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, source.getWidth(), source.getHeight()); final RectF rectF = new RectF(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawOval(rectF, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(source, rect, rect, paint); if (recycle) { source.recycle(); } return output; }
From source file:Main.java
/** * Create a rounded corner bitmap from current bitmap * * @param bitmap/*from w w w .j av a 2 s .c o m*/ * @return */ public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) { try { 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 = 50; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(Color.BLACK); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.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 getCroppedBitmap(Bitmap bmp, int radius) { Bitmap sbmp;/*from w w w . j ava2 s .co m*/ if (bmp.getWidth() != radius || bmp.getHeight() != radius) sbmp = Bitmap.createScaledBitmap(bmp, radius, radius, false); else sbmp = bmp; Bitmap output = Bitmap.createBitmap(sbmp.getWidth(), sbmp.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); //final int color = 0xffa19774; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, sbmp.getWidth(), sbmp.getHeight()); paint.setAntiAlias(true); paint.setFilterBitmap(true); paint.setDither(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(Color.parseColor("#BAB399")); canvas.drawCircle(sbmp.getWidth() / 2 + 0.7f, sbmp.getHeight() / 2 + 0.7f, sbmp.getWidth() / 2 + 0.1f, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(sbmp, rect, rect, paint); return output; }
From source file:Main.java
/** * Gets the bitmap with rounded corners/*www.j ava2 s . co m*/ * * @param bitmap Bitmap for processing * @param pixels Picture diameter in pixels * @return Rounded picture */ public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.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 = pixels; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:Main.java
/** * Create rounded corner bitmap./* ww w . j av a 2s . c o m*/ * * @param bitmap bitmap. * @return rounded bitmap. */ public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) { Bitmap source = Bitmap.createScaledBitmap(bitmap, 480, 480, false); Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, source.getWidth(), source.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = source.getWidth(); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(source, rect, rect, paint); return output; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Context context, Bitmap input, int pixels, int w, int h, boolean squareTL, boolean squareTR, boolean squareBL, boolean squareBR) { Bitmap output = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final float densityMultiplier = context.getResources().getDisplayMetrics().density; final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, w, h); final RectF rectF = new RectF(rect); //make sure that our rounded corner is scaled appropriately final float roundPx = pixels * densityMultiplier; paint.setAntiAlias(true);/*from w w w.ja va 2 s . c om*/ canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); //draw rectangles over the corners we want to be square if (squareTL) { canvas.drawRect(0, 0, w / 2, h / 2, paint); } if (squareTR) { canvas.drawRect(w / 2, 0, w, h / 2, paint); } if (squareBL) { canvas.drawRect(0, h / 2, w / 2, h, paint); } if (squareBR) { canvas.drawRect(w / 2, h / 2, w, h, paint); } paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(input, 0, 0, paint); return output; }
From source file:Main.java
public static Bitmap getRoundBitmap(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); Bitmap out = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(out); Paint paint = new Paint(); paint.setColor(Color.WHITE);/*from w ww.jav a 2 s.c o m*/ paint.setAntiAlias(true); canvas.drawCircle(width / 2, height / 2, width / 2, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); Rect rect = new Rect(0, 0, width, height); canvas.drawBitmap(bitmap, rect, rect, paint); return out; }
From source file:Main.java
public static Bitmap mergeBitmap(Bitmap oriBmp, Bitmap subBmp) { if (subBmp == null) { return oriBmp; }/*from ww w . j ava 2 s .co m*/ if (oriBmp == null) { return null; } return mergeBitmap(oriBmp, subBmp, new Rect(0, 0, oriBmp.getWidth(), oriBmp.getHeight()), new Rect(0, 0, subBmp.getWidth(), subBmp.getHeight())); }
From source file:Main.java
/** * Create circle image./*from w w w . j a v a2s . c om*/ * * @param bitmap Bitmap to be cropped * @param resColor Resource color * @param strokeWidth Thickness of stroke * @return Returns the circle image with border */ public static Bitmap getCircleImage(Bitmap bitmap, int resColor, int strokeWidth) { // create Bitmap to draw Bitmap mBitmap = Bitmap.createBitmap(bitmap.getWidth() + 8, bitmap.getHeight() + 8, Bitmap.Config.ARGB_8888); // create Rect to hold image final Rect mRec = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); // create Canvas Canvas mCanvas = new Canvas(mBitmap); mCanvas.drawARGB(0, 0, 0, 0); // create Paint final Paint mPaint = new Paint(); mPaint.setStyle(Paint.Style.FILL); mPaint.setAntiAlias(true); // get the half size of the image int mHalfWidth = bitmap.getWidth() / 2; int mHalfHeight = bitmap.getHeight() / 2; // draw circle mCanvas.drawCircle((mHalfWidth + 4), (mHalfHeight + 4), Math.min(mHalfWidth, mHalfHeight), mPaint); // unknown mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); // draw the image mCanvas.drawBitmap(bitmap, mRec, mRec, mPaint); // set border mode mPaint.setXfermode(null); // set stroke mPaint.setStyle(Paint.Style.STROKE); // set stroke color mPaint.setColor(resColor); // set stroke width mPaint.setStrokeWidth(strokeWidth); // draw stroke mCanvas.drawCircle((mHalfWidth + 4), (mHalfHeight + 4), Math.min(mHalfWidth, mHalfHeight), mPaint); // return the circle image return mBitmap; }