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 clipRoundCornerBitmap(Bitmap bitmap, float radius, int borderColor) { if (bitmap == null) { return null; }// ww w. j a v a 2s . c o m final int h = bitmap.getHeight(); final int w = bitmap.getWidth(); final Bitmap output = Bitmap.createBitmap(w, h, Config.ARGB_8888); final Canvas canvas = new Canvas(output); final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, w, h); final RectF rectF = new RectF(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(borderColor); canvas.drawRoundRect(rectF, radius, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(final Bitmap bitmap, final float roundPx) { if (bitmap != null) { try {//w w w .j a v a 2s . co m final 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(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; } catch (OutOfMemoryError e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } return bitmap; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Bitmap output = Bitmap.createBitmap(w, h, 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, w, h); final RectF rectF = new RectF(rect); paint.setAntiAlias(true);/*from ww w . j av a 2 s. c om*/ 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
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float cornerRadius) { if (bitmap == null) { return null; }//ww w. j av a 2s . c o m Bitmap result = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(result); 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.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG)); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, cornerRadius, cornerRadius, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(result, rect, rect, paint); return result; }
From source file:Main.java
public static Bitmap getRoundedRectBitmap(Bitmap bitmap) { Bitmap result = null;//from ww w . j a va 2s . c om Canvas canvas; Paint paint; try { final int width = bitmap.getWidth(); final int height = bitmap.getHeight(); result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); canvas = new Canvas(result); int color = 0xff424242; float radius = width > height ? width / 2 : height / 2; paint = new Paint(); Rect rect = new Rect(0, 0, width, height); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawCircle(width / 2, height / 2, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); } catch (NullPointerException | OutOfMemoryError e) { e.printStackTrace(); } return result; }
From source file:Main.java
/** * Get a rectangle for the given 4 points (x0,y0,x1,y1,x2,y2,x3,y3) by finding the min/max 2 points that * contains the given 4 points and is a stright rectangle. *//* w ww.j a va 2 s .c o m*/ static Rect getRectFromPoints(float[] points, int imageWidth, int imageHeight, boolean fixAspectRatio, int aspectRatioX, int aspectRatioY) { int left = Math.round(Math.max(0, getRectLeft(points))); int top = Math.round(Math.max(0, getRectTop(points))); int right = Math.round(Math.min(imageWidth, getRectRight(points))); int bottom = Math.round(Math.min(imageHeight, getRectBottom(points))); Rect rect = new Rect(left, top, right, bottom); if (fixAspectRatio) { fixRectForAspectRatio(rect, aspectRatioX, aspectRatioY); } return rect; }
From source file:Main.java
static Bitmap generatorContactCountIcon(Context context, Bitmap icon) { int iconSize = (int) context.getResources().getDimension(android.R.dimen.app_icon_size); Bitmap contactIcon = Bitmap.createBitmap(iconSize, iconSize, Config.ARGB_8888); Canvas canvas = new Canvas(contactIcon); Paint iconPaint = new Paint(); iconPaint.setDither(true);//from w w w .j a v a2s. com iconPaint.setFilterBitmap(true); Rect src = new Rect(0, 0, icon.getWidth(), icon.getHeight()); Rect dst = new Rect(0, 0, iconSize, iconSize); canvas.drawBitmap(icon, src, dst, iconPaint); int contacyCount = 11; Paint countPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG); countPaint.setColor(Color.RED); countPaint.setTextSize(20f); countPaint.setTypeface(Typeface.DEFAULT_BOLD); canvas.drawText(String.valueOf(contacyCount), iconSize - 18, 25, countPaint); return contactIcon; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Context context, Bitmap bitmap, int color) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); color = 0xff424242; // FIXME 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 = convertDipsToPixels(context, ROUND_DIPS); paint.setAntiAlias(true);// w w w .j av a2s .c o m 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; }
From source file:Main.java
public static Bitmap getScaledCircleCroppedBitmap(Bitmap bitmap, int destSize) { if (bitmap == null) return null; Bitmap output = Bitmap.createBitmap(destSize, destSize, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final int srcSize = Math.min(bitmap.getWidth(), bitmap.getHeight()); final int srcX = (bitmap.getWidth() - srcSize) / 2; final int srcY = (bitmap.getHeight() - srcSize) / 2; final Rect srcRect = new Rect(srcX, srcY, srcX + srcSize, srcY + srcSize); final Rect destRect = new Rect(0, 0, destSize, destSize); final int color = 0xff424242; final Paint paint = new Paint(); paint.setAntiAlias(true);/* w w w. j av a2 s .c o m*/ canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawCircle(destSize / 2, destSize / 2, destSize / 2, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, srcRect, destRect, paint); return output; }
From source file:Main.java
public static Bitmap createRoundedBottomBitmap(Context context, int width, int height, int color) { Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(output); //color = 0x80424242; // FIXME final Paint paint = new Paint(); final int roundPxInt = convertDipsToPixels(context, ROUND_DIPS); final Rect rect = new Rect(0, 0, width, height - roundPxInt); final RectF rectF = new RectF(rect); final Rect rectRound = new Rect(roundPxInt, height - roundPxInt, width - roundPxInt, height); final RectF rectFRound = new RectF(rectRound); paint.setAntiAlias(true);//from ww w. j a v a 2 s. c o m paint.setColor(color); canvas.drawARGB(0, 0, 0, 0); // Corners Rect oval = new Rect(0, height - 2 * roundPxInt, 2 * roundPxInt, height); RectF ovalF = new RectF(oval); canvas.drawArc(ovalF, 90.0f, 90.0f, true, paint); oval = new Rect(width - 2 * roundPxInt, height - 2 * roundPxInt, width, height); ovalF = new RectF(oval); canvas.drawArc(ovalF, 0.0f, 90.0f, true, paint); // Big and small rectangles canvas.drawRect(rectF, paint); canvas.drawRect(rectFRound, paint); return output; }