Example usage for android.graphics RectF height

List of usage examples for android.graphics RectF height

Introduction

In this page you can find the example usage for android.graphics RectF height.

Prototype

public final float height() 

Source Link

Usage

From source file:Main.java

/**
 * Calculates the aspect ratio given a rectangle.
 *///w  w  w .  j av  a 2  s .c  om
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;//from ww w.  j  a  v  a  2 s  .  co m
    }
    canvas.drawRect(rect, PAINT);
}

From source file:Main.java

/**
 * Post translates the matrix to center the given bounds inside the view.
 *//* w  ww. j  a  v a 2 s  .  c o  m*/
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

/**
 * Creates a mutable bitmap from subset of source bitmap, transformed by the optional matrix.
 */// w w  w. j  a  v a2s.co 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;
}

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./*from  w w w  .ja  v a 2  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 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;/*w  ww .ja v a 2s  . co 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

public static Bitmap cropImage(RectF rect, Bitmap bitmap) {
    float width = rect.width() * 2;
    if (width > bitmap.getWidth()) {
        width = bitmap.getWidth();//ww  w . j ava 2  s  .  c o m
    }

    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

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;//from w  ww . ja  v  a 2 s. c  o  m

    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

/**
 * Gets straighten matrix for the given bounds and degrees.
 *///from ww w .j  a v  a  2 s.c om
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);
    }
}