Example usage for android.graphics Rect height

List of usage examples for android.graphics Rect height

Introduction

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

Prototype

public final int height() 

Source Link

Usage

From source file:Main.java

public static int getTextHeightByBounds(String text, float textSize) {
    Paint paint = new Paint();
    Rect bounds = new Rect();
    paint.setTextSize(textSize);/*  w  ww . j av a  2  s  .co  m*/
    paint.getTextBounds(text, 0, text.length(), bounds);
    return bounds.height();
}

From source file:Main.java

public static int getColorOnBitmap(Bitmap src, Rect serchRect, int defaultColor) {
    int width = serchRect.width();
    int height = serchRect.height();

    //        Log.d("getColorOnBitmap", String.format("bitmap width = (%s), height = (%s), Rect = (%s)", src.getWidth()
    //                                                   , src.getHeight(), serchRect.toString()));

    if (width == 0 || height == 0)
        return defaultColor;

    if (width == 1 && height == 1) {
        return src.getPixel(serchRect.left, serchRect.top);
    }//  w w w  . j  a  va  2  s  .c  om
    if (width == 1 && height > 1) {
        int colorMerge = 0xffffffff;
        for (int start = 0; start < height; ++start) {
            colorMerge = colorMerge & src.getPixel(serchRect.left, serchRect.top + start);
        }
        return colorMerge;
    }
    if (width > 1 && height == 1) {
        int colorMerge = 0xffffffff;
        for (int start = 0; start < width; ++start) {
            colorMerge = colorMerge & src.getPixel(serchRect.left + start, serchRect.top);
        }
        return colorMerge;
    }
    if (width > 1 && height > 1) {
        int colorMerge = 0xffffffff;
        for (int x = 0; x < width; ++x) {
            for (int y = 0; y < height; ++y) {
                colorMerge = colorMerge & src.getPixel(serchRect.left + x, serchRect.top + y);
            }
        }
        return colorMerge;
    }

    return defaultColor;
}

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

public static int hasColorOnRect(Bitmap src, Rect serchRect, int inputColor) {
    int width = serchRect.width();
    int height = serchRect.height();

    if (width == 0 || height == 0)
        return inputColor;

    int color = inputColor;
    if (width == 1 && height == 1) {
        color = src.getPixel(serchRect.left, serchRect.top);
        return color != inputColor ? color : inputColor;
    }//from w  ww. j a  v a 2s.  c om
    if (width == 1 && height > 1) {
        for (int start = 0; start < height; ++start) {
            color = src.getPixel(serchRect.left, serchRect.top + start);
            if (color != inputColor)
                return color;
        }
        return inputColor;
    }
    if (width > 1 && height == 1) {
        for (int start = 0; start < width; ++start) {
            color = src.getPixel(serchRect.left + start, serchRect.top);
            if (color != inputColor)
                return color;
        }
        return inputColor;
    }
    if (width > 1 && height > 1) {
        for (int x = 0; x < width; ++x) {
            for (int y = 0; y < height; ++y) {
                color = src.getPixel(serchRect.left + x, serchRect.top + y);
                if (color != inputColor)
                    return color;
            }
        }

        return inputColor;
    }

    return inputColor;
}

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.
 *///  w ww. ja va  2 s .  com
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 drawButtonText(Canvas canvas, Paint paint, Rect btnRect, String text) {
    int nLen = text.length();
    canvas.drawText(text, btnRect.left + btnRect.width() / 2 - 4 * nLen,
            btnRect.top + btnRect.height() / 2 + nLen, paint);
}

From source file:Main.java

/**
 * /*from ww  w  .  java  2  s.  com*/
 * 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

/**
 * convenience method to calculate the y offset for aligning
 * text vertically in its containing Sprite
 *
 * @param {int} yPos y-coordinate of the Sprite / "container" holding the text
 * @param {int} spriteHeight height of the Sprite / "container" holding the text
 * @param {String} text to render//www.  j  av a2  s.co m
 * @param {Paint} textPaint the Paint used to render the text
 *
 * @return {int} the y coordinate for drawing the text
 */
public static int alignTextVertically(int yPos, int spriteHeight, String text, Paint textPaint) {
    final Rect bounds = new Rect();
    textPaint.getTextBounds(text, 0, text.length(), bounds);

    return yPos + (spriteHeight / 2) + (bounds.height() / 2);
}

From source file:Main.java

/**
 * Calculates sensor crop region for a zoom level (zoom >= 1.0).
 *
 * @return Crop region.//from  w ww.  j ava2  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

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();/*from w w  w .  ja  v  a 2  s  .co  m*/
    size[1] = outRect.height();
    return size;
}