Java Code Examples for android.graphics.RectF#roundOut()

The following examples show how to use android.graphics.RectF#roundOut() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompositorViewHolder.java    From delion with Apache License 2.0 6 votes vote down vote up
private Rect rectToPx(RectF rect) {
    rect.roundOut(mPixelRect);
    mPixelRect.left = (int) (mPixelRect.left * mDpToPx);
    mPixelRect.top = (int) (mPixelRect.top * mDpToPx);
    mPixelRect.right = (int) (mPixelRect.right * mDpToPx);
    mPixelRect.bottom = (int) (mPixelRect.bottom * mDpToPx);

    // Don't let any zero sized rects through, they'll cause parent
    // size errors in L.
    if (mPixelRect.width() == 0) {
        mPixelRect.right = mPixelRect.left + 1;
    }
    if (mPixelRect.height() == 0) {
        mPixelRect.bottom = mPixelRect.top + 1;
    }
    return mPixelRect;
}
 
Example 2
Source File: CompositorViewHolder.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private Rect rectToPx(RectF rect) {
    rect.roundOut(mPixelRect);
    mPixelRect.left = (int) (mPixelRect.left * mDpToPx);
    mPixelRect.top = (int) (mPixelRect.top * mDpToPx);
    mPixelRect.right = (int) (mPixelRect.right * mDpToPx);
    mPixelRect.bottom = (int) (mPixelRect.bottom * mDpToPx);

    // Don't let any zero sized rects through, they'll cause parent
    // size errors in L.
    if (mPixelRect.width() == 0) {
        mPixelRect.right = mPixelRect.left + 1;
    }
    if (mPixelRect.height() == 0) {
        mPixelRect.bottom = mPixelRect.top + 1;
    }
    return mPixelRect;
}
 
Example 3
Source File: CompositorViewHolder.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private Rect rectToPx(RectF rect) {
    rect.roundOut(mPixelRect);
    mPixelRect.left = (int) (mPixelRect.left * mDpToPx);
    mPixelRect.top = (int) (mPixelRect.top * mDpToPx);
    mPixelRect.right = (int) (mPixelRect.right * mDpToPx);
    mPixelRect.bottom = (int) (mPixelRect.bottom * mDpToPx);

    // Don't let any zero sized rects through, they'll cause parent
    // size errors in L.
    if (mPixelRect.width() == 0) {
        mPixelRect.right = mPixelRect.left + 1;
    }
    if (mPixelRect.height() == 0) {
        mPixelRect.bottom = mPixelRect.top + 1;
    }
    return mPixelRect;
}
 
Example 4
Source File: MapView.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void invalidateMapCoordinates(final RectF dirty) {
    dirty.roundOut(mInvalidateRect);
    final int width_2 = this.getWidth() / 2;
    final int height_2 = this.getHeight() / 2;

    // Since the canvas is shifted by getWidth/2, we can just return our natural scrollX/Y value
    // since that is the same as the shifted center.
    int centerX = this.getScrollX();
    int centerY = this.getScrollY();

    if (this.getMapOrientation() != 0) {
        GeometryMath.getBoundingBoxForRotatedRectangle(mInvalidateRect, centerX, centerY,
                this.getMapOrientation() + 180, mInvalidateRect);
    }
    mInvalidateRect.offset(width_2, height_2);

    super.invalidate(mInvalidateRect);
}
 
Example 5
Source File: AndroidCamera2Settings.java    From Camera2 with Apache License 2.0 5 votes vote down vote up
/**
 * Calculate the effective crop rectangle for this preview viewport;
 * assumes the preview is centered to the sensor and scaled to fit across one of the dimensions
 * without skewing.
 *
 * <p>Assumes the zoom level of the provided desired crop rectangle.</p>
 *
 * @param requestedCrop Desired crop rectangle, in active array space.
 * @param previewSize Size of the preview buffer render target, in pixels (not in sensor space).
 * @return A rectangle that serves as the preview stream's effective crop region (unzoomed), in
 *          sensor space.
 *
 * @throws NullPointerException
 *          If any of the args were {@code null}.
 */
private static Rect effectiveCropRectFromRequested(Rect requestedCrop, Size previewSize) {
    float aspectRatioArray = requestedCrop.width() * 1.0f / requestedCrop.height();
    float aspectRatioPreview = previewSize.width() * 1.0f / previewSize.height();

    float cropHeight, cropWidth;
    if (aspectRatioPreview < aspectRatioArray) {
        // The new width must be smaller than the height, so scale the width by AR
        cropHeight = requestedCrop.height();
        cropWidth = cropHeight * aspectRatioPreview;
    } else {
        // The new height must be smaller (or equal) than the width, so scale the height by AR
        cropWidth = requestedCrop.width();
        cropHeight = cropWidth / aspectRatioPreview;
    }

    Matrix translateMatrix = new Matrix();
    RectF cropRect = new RectF(/*left*/0, /*top*/0, cropWidth, cropHeight);

    // Now center the crop rectangle so its center is in the center of the active array
    translateMatrix.setTranslate(requestedCrop.exactCenterX(), requestedCrop.exactCenterY());
    translateMatrix.postTranslate(-cropRect.centerX(), -cropRect.centerY());

    translateMatrix.mapRect(/*inout*/cropRect);

    // Round the rect corners towards the nearest integer values
    Rect result = new Rect();
    cropRect.roundOut(result);
    return result;
}
 
Example 6
Source File: CropActivity.java    From imageCrop with MIT License 5 votes vote down vote up
protected static Bitmap getCroppedImage(Bitmap image, RectF cropBounds, RectF photoBounds) {
    RectF imageBounds = new RectF(0, 0, image.getWidth(), image.getHeight());
    RectF crop = CropMath.getScaledCropBounds(cropBounds, photoBounds, imageBounds);
    if (crop == null) {
        return null;
    }
    Rect intCrop = new Rect();
    crop.roundOut(intCrop);
    return Bitmap.createBitmap(image, intCrop.left, intCrop.top, intCrop.width(),
            intCrop.height());
}
 
Example 7
Source File: ParamsUtils.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Create a {@link Rect} from a {@code RectF} by creating a new rectangle with
 * each corner (left, top, right, bottom) rounded towards the nearest integer bounding box.
 *
 * <p>In particular (left, top) is floored, and (right, bottom) is ceiled.</p>
 *
 * @param size a non-{@code null} rect
 *
 * @return a {@code non-null} rectangle
 *
 * @throws NullPointerException if {@code rect} was {@code null}
 */
public static Rect createRect(RectF rect) {
    checkNotNull(rect, "rect must not be null");

    Rect r = new Rect();
    rect.roundOut(r);

    return r;
}