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

public static int getSampleSizeOfNotTooLarge(Rect rect) {
    final int FIVE_M = 5 * 1024 * 1024;
    double ratio = ((double) rect.width()) * rect.height() * 2 / FIVE_M;
    return ratio >= 1 ? (int) ratio : 1;
}

From source file:Main.java

public static float calculateScale(Rect startBounds, Rect finalBounds) {

    float scale;//from  ww  w.j  av  a  2 s.com
    if ((float) finalBounds.width() / finalBounds.height() > (float) startBounds.width()
            / startBounds.height()) {
        /* Extend start bounds horizontally*/
        scale = (float) startBounds.height() / finalBounds.height();
        float startWidth = scale * finalBounds.width();
        float deltaWidth = (startWidth - startBounds.width()) / 2;
        startBounds.left -= deltaWidth;
        startBounds.right += deltaWidth;
    } else {
        /* Extend start bounds vertically*/
        scale = (float) startBounds.width() / finalBounds.width();
        float startHeight = scale * finalBounds.height();
        float deltaHeight = (startHeight - startBounds.height()) / 2;
        startBounds.top -= deltaHeight;
        startBounds.bottom += deltaHeight;
    }

    return scale;
}

From source file:Main.java

public static Rect getBestFitRect(Bitmap bitmap, Rect destination) {
    return getBestFitRect(bitmap, (float) destination.width() / (float) destination.height());
}

From source file:Main.java

public static Bitmap crop(Bitmap bitmap, Rect cropRect) {
    return Bitmap.createBitmap(bitmap, cropRect.left, cropRect.top, cropRect.width(), cropRect.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

/**
 * Draw the favicon with dominant color.
 * @param context Context used to create the intent.
 * @param favicon favicon bitmap.// w  ww .  j  a  v  a 2 s  .  c o  m
 * @param canvas Canvas that holds the favicon.
 */
private static void drawFaviconToCanvas(Context context, Bitmap favicon, Canvas canvas) {
    Rect iconBounds = new Rect(0, 0, canvas.getWidth(), canvas.getHeight());
    int faviconSize = iconBounds.width() / 3;
    Bitmap scaledFavicon = Bitmap.createScaledBitmap(favicon, faviconSize, faviconSize, true);
    canvas.drawBitmap(scaledFavicon, iconBounds.exactCenterX() - scaledFavicon.getWidth() / 2.0f,
            iconBounds.exactCenterY() - scaledFavicon.getHeight() / 2.0f, null);
}

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);
    }/*from  w w  w. j  av  a2s  . 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: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 w w. j  a  v a 2  s  . co m*/
    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

public static void drawCenterText(Canvas canvas, String text, Paint paint, Rect rect) {
    paint.getTextBounds(text, 0, text.length(), bounds);
    int x = (int) (rect.left + rect.width() / 2 - bounds.centerX());
    int y = (int) (rect.top + rect.height() / 2 - bounds.centerY());
    //Log.v(TAG," x="+x + " y="+y + " "+ text);
    canvas.drawText(text, x, y, paint);/*  w ww. j  a v  a  2  s  .  c om*/
}

From source file:Main.java

static boolean validSurface(SurfaceHolder holder) {
    if (holder.getSurface() != null) {
        Rect r = holder.getSurfaceFrame();
        System.out.println("ExoVlcUtil.validSurface() r = " + r);
        return (r.width() * r.height()) > 0;
    }/*from  www  .j  a  va2  s  . co  m*/
    return false;
}