Example usage for android.graphics Rect width

List of usage examples for android.graphics Rect width

Introduction

In this page you can find the example usage for android.graphics Rect width.

Prototype

public final int width() 

Source Link

Usage

From source file:Main.java

/**
 * Calculates sensor crop region for a zoom level (zoom >= 1.0).
 *
 * @return Crop region.//  w  ww.  j  av a 2 s  . c o m
 */
public static Rect cropRegionForZoom(CameraCharacteristics characteristics, float zoom) {
    Rect sensor = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
    int xCenter = sensor.width() / 2;
    int yCenter = sensor.height() / 2;
    int xDelta = (int) (0.5f * sensor.width() / zoom);
    int yDelta = (int) (0.5f * sensor.height() / zoom);
    return new Rect(xCenter - xDelta, yCenter - yDelta, xCenter + xDelta, yCenter + yDelta);
}

From source file:Main.java

/**
 * //from   w w  w. ja va2  s.c o m
 * TODO
 * ImageFormat.NV21 || format == ImageFormat.YUY2.
 * @param data
 * @param width
 * @param height
 * @param rect
 * @return
 */
public static Bitmap cropYuv2Bitmap(byte[] data, int width, int height, Rect rect) {
    int w = rect.width();
    int h = rect.height();
    int frameSize = width * height;
    int[] pixels = new int[w * h];
    byte[] yuv = data;
    int yOffset = rect.top * width + rect.left;
    int uvOffset = (rect.top / 2) * width + (rect.left / 2) * 2 + frameSize;
    int y, u, v, k;

    for (int i = 0; i < h; ++i) {
        int outputOffset = i * w;
        for (int j = 0; j < w; ++j) {
            y = (0xff & yuv[yOffset + j]) - 16;

            k = ((j >> 1) << 1);
            v = (0xff & yuv[uvOffset + k]) - 128;
            u = (0xff & yuv[uvOffset + k + 1]) - 128;

            int y1192 = 1192 * y;
            int r = (y1192 + 1634 * v);
            int g = (y1192 - 833 * v - 400 * u);
            int b = (y1192 + 2066 * u);

            if (r < 0)
                r = 0;
            else if (r > 262143)
                r = 262143;
            if (g < 0)
                g = 0;
            else if (g > 262143)
                g = 262143;
            if (b < 0)
                b = 0;
            else if (b > 262143)
                b = 262143;

            pixels[outputOffset + j] = 0xff000000 | ((r << 6) & 0xff0000) | ((g >> 2) & 0xff00)
                    | ((b >> 10) & 0xff);
        }
        yOffset += width;
        if (((rect.top + i) & 1) == 1) {
            uvOffset += width;
        }
    }
    Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, w, 0, 0, w, h);
    return bitmap;
}

From source file:Main.java

public static int[] sizeActivity(Activity activity) {
    int[] size = new int[2];
    Rect outRect = new Rect();
    activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getDrawingRect(outRect);
    size[0] = outRect.width();
    size[1] = outRect.height();// w  ww  . j a  v a  2 s.  c  o  m
    return size;
}

From source file:org.mozilla.gecko.gfx.RectUtils.java

public static IntSize getSize(Rect rect) {
    return new IntSize(rect.width(), rect.height());
}

From source file:Main.java

/**
 * Fix the given rectangle if it doesn't confirm to aspect ration rule.<br>
 * Make sure that width and height are equal if 1:1 fixed aspect ratio is requested.
 *//*from ww w  . j  av  a  2  s .c  om*/
private static void fixRectForAspectRatio(Rect rect, int aspectRatioX, int aspectRatioY) {
    if (aspectRatioX == aspectRatioY && rect.width() != rect.height()) {
        if (rect.height() > rect.width()) {
            rect.bottom -= rect.height() - rect.width();
        } else {
            rect.right -= rect.width() - rect.height();
        }
    }
}

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  ava 2s .  c  om
    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

private static void setTextSizeForWidth(String text, Paint paint, float desiredWidth) {

    final float testTextSize = 48f;
    paint.setTextSize(testTextSize);/*from  www .  j a v  a2  s. co  m*/
    Rect bounds = new Rect();
    paint.getTextBounds(text, 0, text.length(), bounds);
    float desiredTextSize = testTextSize * desiredWidth / bounds.width();
    paint.setTextSize(desiredTextSize);
}

From source file:Main.java

public static int getButtonTextWidth(Button button, String text) {
    Rect bounds = new Rect();
    Paint buttonPaint = button.getPaint();
    buttonPaint.getTextBounds(text, 0, text.length(), bounds);
    return bounds.width();
}

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

/**
 * Method getTextWith() used to get the TextView's Content
 * //w w  w .ja va 2  s.  com
 * @param textView
 *            The processed TextView.
 * @param text
 *            The Content of TextView
 * @return
 */
public static int getTextWidth(TextView textView, String text) {
    Rect bounds = new Rect();
    Paint textPaint = textView.getPaint();
    textPaint.getTextBounds(text, 0, text.length(), bounds);
    return bounds.width();
}