List of usage examples for android.graphics RectF width
public final float width()
From source file:Main.java
public static void drawTextCenter(Canvas canvas, RectF rectf, String s, String s1, Paint paint, Paint paint1) { Rect rect = new Rect(); paint.getTextBounds(s, 0, s.length(), rect); float f = rectf.left + (rectf.width() - (float) rect.width()) / 2.0F; float f1 = rectf.top + (rectf.height() + (float) rect.height()) / 2.0F; canvas.drawText(s, f, f1, paint);/*from w ww . j a v a2 s . co m*/ Rect rect1 = new Rect(); paint1.getTextBounds(s, 0, s.length(), rect1); canvas.drawText(s1, 6F + (f + (float) rect.width()), (f1 - (float) rect.height()) + (float) rect1.height(), paint1); }
From source file:Main.java
/** * Gets straighten matrix for the given bounds and degrees. *//*from w ww . j a va 2 s .c o m*/ public static void getStraightenMatrix(RectF bounds, float degrees, Matrix matrix) { matrix.reset(); if ((degrees != 0) && !bounds.isEmpty()) { float w = bounds.width() / 2; float h = bounds.height() / 2; float adjustAngle; if ((degrees < 0 && w > h) || (degrees > 0 && w <= h)) { // The top left point is the boundary. adjustAngle = (float) Math.atan(h / -w) + MATH_PI + degrees * DEGREES_TO_RADIAN; } else { // The top right point is the boundary. adjustAngle = (float) Math.atan(h / w) - MATH_PI + degrees * DEGREES_TO_RADIAN; } float radius = (float) Math.hypot(w, h); float scaleX = (float) Math.abs(radius * Math.cos(adjustAngle)) / w; float scaleY = (float) Math.abs(radius * Math.sin(adjustAngle)) / h; float scale = Math.max(scaleX, scaleY); postRotateMatrix(degrees, new RectF(bounds), matrix); matrix.postScale(scale, scale); } }
From source file:Main.java
public static void drawRuleOfThird(Canvas canvas, RectF bounds) { Paint p = new Paint(); p.setStyle(Paint.Style.STROKE); p.setColor(Color.argb(128, 255, 255, 255)); p.setStrokeWidth(2);//from w w w . j av a 2s .c o m float stepX = bounds.width() / 3.0f; float stepY = bounds.height() / 3.0f; float x = bounds.left + stepX; float y = bounds.top + stepY; for (int i = 0; i < 2; i++) { canvas.drawLine(x, bounds.top, x, bounds.bottom, p); x += stepX; } for (int j = 0; j < 2; j++) { canvas.drawLine(bounds.left, y, bounds.right, y, p); y += stepY; } }
From source file:org.mozilla.gecko.gfx.RectUtils.java
public static RectF scale(RectF rect, float scale) { float x = rect.left * scale; float y = rect.top * scale; return new RectF(x, y, x + (rect.width() * scale), y + (rect.height() * scale)); }
From source file:com.lcl6.cn.imagepickerl.AndroidImagePicker.java
public static Bitmap makeCropBitmap(Bitmap bitmap, Rect rectBox, RectF imageMatrixRect, int expectSize) { Bitmap bmp = bitmap;//from w ww . j a v a 2 s .c o m RectF localRectF = imageMatrixRect; float f = localRectF.width() / bmp.getWidth(); int left = (int) ((rectBox.left - localRectF.left) / f); int top = (int) ((rectBox.top - localRectF.top) / f); int width = (int) (rectBox.width() / f); int height = (int) (rectBox.height() / f); if (left < 0) { left = 0; } if (top < 0) { top = 0; } if (left + width > bmp.getWidth()) { width = bmp.getWidth() - left; } if (top + height > bmp.getHeight()) { height = bmp.getHeight() - top; } int k = width; if (width < expectSize) { k = expectSize; } if (width > expectSize) { k = expectSize; } try { bmp = Bitmap.createBitmap(bmp, left, top, width, height); if (k != width && k != height) {//don't do this if equals bmp = Bitmap.createScaledBitmap(bmp, k, k, true);//scale the bitmap } } catch (OutOfMemoryError localOutOfMemoryError1) { Log.v(TAG, "OOM when create bitmap"); } return bmp; }
From source file:com.pizidea.imagepicker.AndroidImagePicker.java
public static Bitmap makeCropBitmap(Bitmap bitmap, Rect rectBox, RectF imageMatrixRect, int expectSize) { Bitmap bmp = bitmap;/*from www .j a v a 2 s . c o m*/ RectF localRectF = imageMatrixRect; float f = localRectF.width() / bmp.getWidth(); int left = (int) ((rectBox.left - localRectF.left) / f); int top = (int) ((rectBox.top - localRectF.top) / f); int width = (int) (rectBox.width() / f); int height = (int) (rectBox.height() / f); if (left < 0) { left = 0; } if (top < 0) { top = 0; } if (left + width > bmp.getWidth()) { width = bmp.getWidth() - left; } if (top + height > bmp.getHeight()) { height = bmp.getHeight() - top; } int k = width; if (width < expectSize) { k = expectSize; } if (width > expectSize) { k = expectSize; } try { bmp = Bitmap.createBitmap(bmp, left, top, width, height); if (k != width && k != height) {//don't do this if equals bmp = Bitmap.createScaledBitmap(bmp, k, k, true);//scale the bitmap } } catch (OutOfMemoryError localOutOfMemoryError1) { Log.v(TAG, "OOM when create bitmap"); } return bmp; }
From source file:android.support.wear.widget.util.ArcSwipe.java
public ArcSwipe(Gesture gesture, RectF bounds) { Preconditions.checkArgument(bounds.height() == bounds.width()); mGesture = gesture; mBounds = bounds; }
From source file:org.mozilla.gecko.gfx.ViewportMetrics.java
public PointF getOptimumViewportOffset(IntSize displayportSize) { /* XXX Until bug #524925 is fixed, changing the viewport origin will * cause unnecessary relayouts. This may cause rendering time to * increase and should be considered. *//*from w ww .jav a 2s.com*/ RectF viewport = getClampedViewport(); FloatSize bufferSpace = new FloatSize(displayportSize.width - viewport.width(), displayportSize.height - viewport.height()); PointF optimumOffset = new PointF(bufferSpace.width * ((mViewportBias.x + 1.0f) / 2.0f), bufferSpace.height * ((mViewportBias.y + 1.0f) / 2.0f)); // Make sure this offset won't cause wasted pixels in the displayport // (i.e. make sure the resultant displayport intersects with the page // as much as possible) if (viewport.left - optimumOffset.x < 0) optimumOffset.x = viewport.left; else if ((bufferSpace.width - optimumOffset.x) + viewport.right > mPageSize.width) optimumOffset.x = bufferSpace.width - (mPageSize.width - viewport.right); if (viewport.top - optimumOffset.y < 0) optimumOffset.y = viewport.top; else if ((bufferSpace.height - optimumOffset.y) + viewport.bottom > mPageSize.height) optimumOffset.y = bufferSpace.height - (mPageSize.height - viewport.bottom); return new PointF(Math.round(optimumOffset.x), Math.round(optimumOffset.y)); }
From source file:com.iped.ipcam.bitmapfun.ImageDetailFragment.java
protected void center(boolean horizontal, boolean vertical) { Matrix m = new Matrix(); m.set(matrix);//from w w w . j av a 2 s . c o m RectF rect = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight()); m.mapRect(rect); float height = rect.height(); float width = rect.width(); float deltaX = 0, deltaY = 0; if (vertical) { int screenHeight = dm.heightPixels; if (height <= screenHeight) { deltaY = (screenHeight - height) / 2 - rect.top; } else if (rect.top > 0) { deltaY = -rect.top; } else if (rect.bottom < screenHeight) { deltaY = screenHeight - rect.bottom; } } if (horizontal) { int screenWidth = dm.widthPixels; if (width <= screenWidth) { deltaX = (screenWidth - width) / 2 - rect.left; } else if (rect.left > 0) { deltaX = -rect.left; } else if (rect.right < screenWidth) { deltaX = screenWidth - rect.right; } } matrix.postTranslate(deltaX, deltaY); }
From source file:com.android.camera.HighlightView.java
private void growBy(float dx, float dy) { if (mMaintainAspectRatio) { if (dx != 0) { dy = dx / mInitialAspectRatio; } else if (dy != 0) { dx = dy * mInitialAspectRatio; }// w w w. j ava 2s.c o m } // Don't let the cropping rectangle grow too fast. // Grow at most half of the difference between the image rectangle and // the cropping rectangle. RectF r = new RectF(mCropRect); if (dx > 0F && r.width() + 2 * dx > mImageRect.width()) { dx = (mImageRect.width() - r.width()) / 2F; if (mMaintainAspectRatio) { dy = dx / mInitialAspectRatio; } } if (dy > 0F && r.height() + 2 * dy > mImageRect.height()) { dy = (mImageRect.height() - r.height()) / 2F; if (mMaintainAspectRatio) { dx = dy * mInitialAspectRatio; } } r.inset(-dx, -dy); // Don't let the cropping rectangle shrink too fast. final float widthCap = 25F; if (r.width() < widthCap) { r.inset(-(widthCap - r.width()) / 2F, 0F); } float heightCap = mMaintainAspectRatio ? (widthCap / mInitialAspectRatio) : widthCap; if (r.height() < heightCap) { r.inset(0F, -(heightCap - r.height()) / 2F); } // Put the cropping rectangle inside the image rectangle. if (r.left < mImageRect.left) { r.offset(mImageRect.left - r.left, 0F); } else if (r.right > mImageRect.right) { r.offset(-(r.right - mImageRect.right), 0); } if (r.top < mImageRect.top) { r.offset(0F, mImageRect.top - r.top); } else if (r.bottom > mImageRect.bottom) { r.offset(0F, -(r.bottom - mImageRect.bottom)); } mCropRect.set(r); mDrawRect = computeLayout(); mContext.invalidate(); }