List of usage examples for android.graphics RectF width
public final float width()
From source file:Main.java
/** * Calculates the aspect ratio given a rectangle. *///from w ww .j a va 2 s . co m public static float calculateAspectRatio(@NonNull RectF rect) { return rect.width() / rect.height(); }
From source file:Main.java
private static void clearCanvas(Canvas canvas, RectF rect) { if (rect.width() <= 0 || rect.height() <= 0) { return;/*w ww. j a v a 2s . c o m*/ } canvas.drawRect(rect, PAINT); }
From source file:Main.java
public static Bitmap cropImage(RectF rect, Bitmap bitmap) { float width = rect.width() * 2; if (width > bitmap.getWidth()) { width = bitmap.getWidth();//from w w w . ja va 2 s.c om } float hight = rect.height() * 2; if (hight > bitmap.getHeight()) { hight = bitmap.getHeight(); } float l = rect.centerX() - (width / 2); if (l < 0) { l = 0; } float t = rect.centerY() - (hight / 2); if (t < 0) { t = 0; } if (l + width > bitmap.getWidth()) { width = bitmap.getWidth() - l; } if (t + hight > bitmap.getHeight()) { hight = bitmap.getHeight() - t; } return Bitmap.createBitmap(bitmap, (int) l, (int) t, (int) width, (int) hight); }
From source file:Main.java
/** * Post translates the matrix to center the given bounds inside the view. *///from ww w .j av a 2 s. c om public static void postCenterMatrix(RectF contentBounds, View view, Matrix matrix) { matrix.postTranslate((view.getWidth() - contentBounds.width()) / 2, (view.getHeight() - contentBounds.height()) / 2); }
From source file:Main.java
public static void log(String key, RectF rect) { debugOutput.put(key, rect.left + ", " + rect.top + ", " + rect.right + ", " + rect.bottom + " : " + rect.width() + ", " + rect.height()); }
From source file:Main.java
/** * Gets the proper scale value that scales down the content and keeps its aspect ratio to * display inside the view.//w w w .j a v a2 s . c o m */ public static float getDisplayScale(RectF contentBounds, View view) { if (contentBounds.isEmpty()) { return 1; } float scale = Math.min(view.getWidth() / contentBounds.width(), view.getHeight() / contentBounds.height()); // Avoid scaling up the content. return Math.min(scale, 1); }
From source file:Main.java
public static void drawTextCenter(Canvas canvas, RectF rectf, String s, Paint paint) { Rect rect = new Rect(); paint.getTextBounds(s, 0, s.length(), rect); canvas.drawText(s, rectf.left + (rectf.width() - (float) rect.width()) / 2.0F, rectf.top + (rectf.height() + (float) rect.height()) / 2.0F, paint); }
From source file:Main.java
public static void drawWallpaperSelectionFrame(Canvas canvas, RectF cropBounds, float spotX, float spotY, Paint p, Paint shadowPaint) { float sx = cropBounds.width() * spotX; float sy = cropBounds.height() * spotY; float cx = cropBounds.centerX(); float cy = cropBounds.centerY(); RectF r1 = new RectF(cx - sx / 2, cy - sy / 2, cx + sx / 2, cy + sy / 2); float temp = sx; sx = sy;//from w w w . ja va2s .c o m sy = temp; RectF r2 = new RectF(cx - sx / 2, cy - sy / 2, cx + sx / 2, cy + sy / 2); canvas.save(); canvas.clipRect(cropBounds); canvas.clipRect(r1, Region.Op.DIFFERENCE); canvas.clipRect(r2, Region.Op.DIFFERENCE); canvas.drawPaint(shadowPaint); canvas.restore(); Path path = new Path(); path.moveTo(r1.left, r1.top); path.lineTo(r1.right, r1.top); path.moveTo(r1.left, r1.top); path.lineTo(r1.left, r1.bottom); path.moveTo(r1.left, r1.bottom); path.lineTo(r1.right, r1.bottom); path.moveTo(r1.right, r1.top); path.lineTo(r1.right, r1.bottom); path.moveTo(r2.left, r2.top); path.lineTo(r2.right, r2.top); path.moveTo(r2.right, r2.top); path.lineTo(r2.right, r2.bottom); path.moveTo(r2.left, r2.bottom); path.lineTo(r2.right, r2.bottom); path.moveTo(r2.left, r2.top); path.lineTo(r2.left, r2.bottom); canvas.drawPath(path, p); }
From source file:Main.java
private static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height, Matrix m, float offset, boolean clipShadow, Paint paint) { int scaledWidth = width; int scaledHeight = height; final Canvas canvas = new Canvas(); canvas.translate(offset / 2.0f, offset / 2.0f); Bitmap bitmap;// ww w . ja v a2s. c om final Rect from = new Rect(x, y, x + width, y + height); final RectF to = new RectF(0, 0, width, height); if (m == null || m.isIdentity()) { bitmap = Bitmap.createBitmap(scaledWidth + (int) offset, scaledHeight + (int) (clipShadow ? (offset / 2.0f) : offset), Bitmap.Config.ARGB_8888); paint = null; } else { RectF mapped = new RectF(); m.mapRect(mapped, to); scaledWidth = Math.round(mapped.width()); scaledHeight = Math.round(mapped.height()); bitmap = Bitmap.createBitmap(scaledWidth + (int) offset, scaledHeight + (int) (clipShadow ? (offset / 2.0f) : offset), Bitmap.Config.ARGB_8888); canvas.translate(-mapped.left, -mapped.top); canvas.concat(m); } canvas.setBitmap(bitmap); canvas.drawRect(0.0f, 0.0f, width, height, paint); canvas.drawBitmap(source, from, to, SCALE_PAINT); return bitmap; }
From source file:Main.java
/** * Creates a mutable bitmap from subset of source bitmap, transformed by the optional matrix. *///from w w w. j av a 2 s . c o m private static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height, Matrix m) { // Re-implement Bitmap createBitmap() to always return a mutable bitmap. Canvas canvas = new Canvas(); Bitmap bitmap; Paint paint; if ((m == null) || m.isIdentity()) { bitmap = Bitmap.createBitmap(width, height, source.getConfig()); paint = null; } else { RectF rect = new RectF(0, 0, width, height); m.mapRect(rect); bitmap = Bitmap.createBitmap(Math.round(rect.width()), Math.round(rect.height()), source.getConfig()); canvas.translate(-rect.left, -rect.top); canvas.concat(m); paint = new Paint(Paint.FILTER_BITMAP_FLAG); if (!m.rectStaysRect()) { paint.setAntiAlias(true); } } bitmap.setDensity(source.getDensity()); canvas.setBitmap(bitmap); Rect srcBounds = new Rect(x, y, x + width, y + height); RectF dstBounds = new RectF(0, 0, width, height); canvas.drawBitmap(source, srcBounds, dstBounds, paint); return bitmap; }