List of usage examples for android.graphics Rect Rect
public Rect(int left, int top, int right, int bottom)
From source file:Main.java
private static Bitmap toBitmap(Drawable drawable, int width, int height) { Bitmap bmp = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas c = new Canvas(bmp); drawable.setBounds(new Rect(0, 0, width, height)); drawable.draw(c);// ww w . j a va 2s.c o m return bmp; }
From source file:Main.java
public static synchronized void cleansurfaceview(SurfaceHolder postureholder, SurfaceView posturesurface) { Canvas canvas = postureholder .lockCanvas(new Rect(0, 0, posturesurface.getWidth(), posturesurface.getHeight())); canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); postureholder.unlockCanvasAndPost(canvas); Canvas canvasa = postureholder .lockCanvas(new Rect(0, 0, posturesurface.getWidth(), posturesurface.getHeight())); canvasa.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); postureholder.unlockCanvasAndPost(canvasa); }
From source file:Main.java
public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) { 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 = pixels; paint.setAntiAlias(true);/*from w ww .j a v a 2s . co 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
/** * <pre>/* w ww. ja v a 2 s. c om*/ * Determine whether a {@link MotionEvent} is on a {@link View} * </pre> */ public static boolean motionEventOnView(MotionEvent event, View view) { int[] location = new int[2]; view.getLocationOnScreen(location); int x = location[0]; int y = location[1]; int w = view.getWidth(); int h = view.getHeight(); Rect rect = new Rect(x, y, x + w, y + h); return rect.contains((int) event.getRawX(), (int) event.getRawY()); }
From source file:Main.java
/** * Draw the favicon with dominant color. * @param context Context used to create the intent. * @param favicon favicon bitmap./*w w w. j a v a 2 s . co m*/ * @param canvas Canvas that holds the favicon. */ private static void drawFaviconToCanvas(Context context, Bitmap favicon, Canvas canvas) { Rect iconBounds = new Rect(0, 0, canvas.getWidth(), canvas.getHeight()); int faviconSize = iconBounds.width() / 3; Bitmap scaledFavicon = Bitmap.createScaledBitmap(favicon, faviconSize, faviconSize, true); canvas.drawBitmap(scaledFavicon, iconBounds.exactCenterX() - scaledFavicon.getWidth() / 2.0f, iconBounds.exactCenterY() - scaledFavicon.getHeight() / 2.0f, null); }
From source file:Main.java
public static Bitmap formatUserAvatar(Bitmap photo) { int maskColor = 0xff424242; Paint cornerPaint = new Paint(); cornerPaint.setAntiAlias(true);/* w w w .ja v a 2s .com*/ cornerPaint.setColor(maskColor); Rect roundedCornerRect = new Rect(0, 0, 256, 256); RectF roundedCornerRectF = new RectF(roundedCornerRect); Bitmap roundedCornerBitmap = Bitmap.createBitmap(256, 256, Bitmap.Config.ARGB_8888); Canvas roundedCornerCanvas = new Canvas(roundedCornerBitmap); roundedCornerCanvas.drawARGB(0, 0, 0, 0); roundedCornerCanvas.drawRoundRect(roundedCornerRectF, 128, 128, cornerPaint); cornerPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); Bitmap scaledBitmap = Bitmap.createScaledBitmap(photo, 256, 256, true); roundedCornerCanvas.drawBitmap(scaledBitmap, roundedCornerRect, roundedCornerRect, cornerPaint); return roundedCornerBitmap; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float ratio) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.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);// www .j a v a 2 s . c om canvas.drawARGB(0, 0, 0, 0); canvas.drawRoundRect(rectF, bitmap.getWidth() / ratio, bitmap.getHeight() / ratio, 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 cropWithCanvas(Bitmap bitmap, Rect cropRect) { Rect destRect = new Rect(0, 0, cropRect.width(), cropRect.height()); Bitmap cropped = Bitmap.createBitmap(cropRect.width(), cropRect.height(), Bitmap.Config.RGB_565); Canvas canvas = new Canvas(cropped); canvas.drawBitmap(bitmap, cropRect, destRect, null); return cropped; }
From source file:Main.java
public static Rect getFittingRectangle(float targetWidth, float targetHeight, float ratio) { //float targetRatio = targetWidth / targetHeight; float scaledWidth = targetWidth; float scaledHeight = scaledWidth / ratio; if (scaledHeight > targetHeight) { scaledHeight = targetHeight;/*from w w w . j a va 2 s .c om*/ scaledWidth = scaledHeight * ratio; } int left = (int) ((targetWidth - scaledWidth) / 2); int top = (int) ((targetHeight - scaledHeight) / 2); return new Rect(left, top, left + (int) scaledWidth, top + (int) scaledHeight); }
From source file:Main.java
public static Bitmap toRoundCorner(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);/* w w w . j av a 2 s. c o m*/ 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; }