Example usage for android.graphics RectF RectF

List of usage examples for android.graphics RectF RectF

Introduction

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

Prototype

public RectF(Rect r) 

Source Link

Usage

From source file:Main.java

/** Convert coordination of face rect to screen rect that will be draw on canvas<br>
 * *//*from   ww  w  . j  ava  2 s  .co  m*/
public static Rect convertFaceRect(Rect faceRect, boolean frontCamera, float displayOrientation,
        float viewWidth, float viewHeight) {

    RectF tmp = new RectF(faceRect);
    Matrix matrix = createConvertMatrix(frontCamera, displayOrientation, viewWidth, viewHeight);
    matrix.mapRect(tmp);
    return new Rect((int) tmp.left, (int) tmp.top, (int) tmp.right, (int) tmp.bottom);
}

From source file:Main.java

public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = pixels;

    paint.setAntiAlias(true);//from w w w  . j  a va2  s  .  c  o  m
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
}

From source file:Main.java

public static Bitmap formatUserAvatar(Bitmap photo) {
    int maskColor = 0xff424242;
    Paint cornerPaint = new Paint();
    cornerPaint.setAntiAlias(true);//from   ww  w  . j ava  2  s  .  com
    cornerPaint.setColor(maskColor);
    Rect roundedCornerRect = new Rect(0, 0, 256, 256);
    RectF roundedCornerRectF = new RectF(roundedCornerRect);
    Bitmap roundedCornerBitmap = Bitmap.createBitmap(256, 256, Bitmap.Config.ARGB_8888);
    Canvas roundedCornerCanvas = new Canvas(roundedCornerBitmap);
    roundedCornerCanvas.drawARGB(0, 0, 0, 0);
    roundedCornerCanvas.drawRoundRect(roundedCornerRectF, 128, 128, cornerPaint);
    cornerPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    Bitmap scaledBitmap = Bitmap.createScaledBitmap(photo, 256, 256, true);
    roundedCornerCanvas.drawBitmap(scaledBitmap, roundedCornerRect, roundedCornerRect, cornerPaint);
    return roundedCornerBitmap;
}

From source file:Main.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float ratio) {

    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);

    paint.setAntiAlias(true);//from  w w  w .j  a v  a2s.com
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawRoundRect(rectF, bitmap.getWidth() / ratio, bitmap.getHeight() / ratio, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}

From source file:Main.java

public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = pixels;
    paint.setAntiAlias(true);/*w w  w .  j a v a 2  s.c o m*/
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}

From source file:Main.java

public static Bitmap bitmap2Round(Bitmap bitmap, float roundPx) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    paint.setAntiAlias(true);//from  w  w  w.  j  av  a  2  s.  c om
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}

From source file:Main.java

public static Bitmap getRoundBitmap(Bitmap bitmap, int pixels) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = pixels;
    paint.setAntiAlias(true);//  w  w  w  .  j a v  a2s  . co  m
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}

From source file:Main.java

public static Bitmap toOvalBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getHeight(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    Paint paint = new Paint();
    paint.setAntiAlias(true);/*  ww w. j a  v  a  2s . co  m*/
    Rect rect = new Rect(0, 0, bitmap.getHeight(), bitmap.getHeight());
    RectF rectF = new RectF(rect);

    canvas.drawOval(rectF, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rectF, paint);
    return output;
}

From source file:Main.java

public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    Canvas canvas = new Canvas(output);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = pixels;
    paint.setAntiAlias(true);//from  ww w .j  a  va  2  s .  co  m
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}

From source file:Main.java

public static Bitmap toRoundedCornerBitmap(Bitmap bitmap, int radius) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    paint.setAntiAlias(true);/*w  w  w . j a v a 2  s  .c  o m*/
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, radius, radius, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}