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:com.example.gatsu.theevent.HighlightView.java

public void setup(Matrix m, Rect imageRect, RectF cropRect, boolean circle, boolean maintainAspectRatio) {

    if (circle) {
        maintainAspectRatio = true;//w  ww .  ja  v a  2 s  . c o  m
    }
    mMatrix = new Matrix(m);

    mCropRect = cropRect;
    mImageRect = new RectF(imageRect);
    mMaintainAspectRatio = maintainAspectRatio;
    mCircle = circle;

    mInitialAspectRatio = mCropRect.width() / mCropRect.height();
    mDrawRect = computeLayout();

    mFocusPaint.setARGB(125, 50, 50, 50);
    mNoFocusPaint.setARGB(125, 50, 50, 50);
    mOutlinePaint.setStrokeWidth(3F);
    mOutlinePaint.setStyle(Paint.Style.STROKE);
    mOutlinePaint.setAntiAlias(true);

    mMode = ModifyMode.None;
    init();
}

From source file:com.mikelau.croperino.HighlightView.java

public void setup(Matrix m, Rect imageRect, RectF cropRect, boolean circle, boolean maintainAspectRatio,
        boolean ovalo) {

    if (circle || ovalo) {
        maintainAspectRatio = true;/*  w  w w. j av  a  2 s .  co m*/
    }

    if (!ovalo) {
        mOvalo = false;
    } else {
        mOvalo = ovalo;
    }

    mMatrix = new Matrix(m);

    mCropRect = cropRect;
    mImageRect = new RectF(imageRect);
    mMaintainAspectRatio = maintainAspectRatio;
    mCircle = circle;

    mInitialAspectRatio = mCropRect.width() / mCropRect.height();
    mDrawRect = computeLayout();

    mFocusPaint.setARGB(125, 50, 50, 50);
    mNoFocusPaint.setARGB(125, 50, 50, 50);
    mOutlinePaint.setStrokeWidth(3F);
    mOutlinePaint.setStyle(Paint.Style.STROKE);
    mOutlinePaint.setAntiAlias(true);

    mMode = ModifyMode.None;
    init();
}

From source file:com.yk.notification.util.BitmapUtil.java

/**
 * /*from w  w w .  ja  va2s.c  om*/
 * 
 * @param bitmap
 *            ?Bitmap
 * @param roundPx
 *            ?
 * @return Bitmap
 */
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) {

    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);

    paint.setAntiAlias(true);
    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:com.tafayor.selfcamerashot.taflib.helpers.GraphicsHelper.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {

    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 = 12;

    paint.setAntiAlias(true);/* w ww.j a v a2 s.c om*/

    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:com.mediatek.galleryfeature.stereo.segment.ImageShow.java

protected void constrainTranslation(Point translation, float scale) {
    int currentEdgeEffect = 0;
    if (scale <= 1) {
        finishEdgeEffect();//  w  w  w  .  j  a  v  a2s. co  m
        return;
    }
    Rect originalBounds = mMasterImage.getOriginalBounds();
    Matrix originalToScreen = mMasterImage.getImageToScreenMatrix(originalBounds.width(),
            originalBounds.height(), getWidth(), getHeight());
    if (originalToScreen == null) {
        finishEdgeEffect();
        return;
    }
    RectF screenPos = new RectF(originalBounds);
    originalToScreen.mapRect(screenPos);
    boolean rightConstraint = screenPos.right < getWidth();
    boolean leftConstraint = screenPos.left > 0;
    boolean topConstraint = screenPos.top > 0;
    boolean bottomConstraint = screenPos.bottom < getHeight();
    if (screenPos.width() > getWidth()) {
        if (rightConstraint && !leftConstraint) {
            float tx = screenPos.right - translation.x * scale;
            translation.x = (int) ((getWidth() - tx) / scale);
            currentEdgeEffect = EDGE_RIGHT;
        } else if (leftConstraint && !rightConstraint) {
            float tx = screenPos.left - translation.x * scale;
            translation.x = (int) ((-tx) / scale);
            currentEdgeEffect = EDGE_LEFT;
        }
    } else {
        float tx = screenPos.right - translation.x * scale;
        float dx = (getWidth() - screenPos.width()) / 2f;
        translation.x = (int) ((getWidth() - tx - dx) / scale);
    }
    if (screenPos.height() > getHeight()) {
        if (bottomConstraint && !topConstraint) {
            float ty = screenPos.bottom - translation.y * scale;
            translation.y = (int) ((getHeight() - ty) / scale);
            currentEdgeEffect = EDGE_BOTTOM;
        } else if (topConstraint && !bottomConstraint) {
            float ty = screenPos.top - translation.y * scale;
            translation.y = (int) ((-ty) / scale);
            currentEdgeEffect = EDGE_TOP;
        }
    } else {
        float ty = screenPos.bottom - translation.y * scale;
        float dy = (getHeight() - screenPos.height()) / 2f;
        translation.y = (int) ((getHeight() - ty - dy) / scale);
    }
    if (mCurrentEdgeEffect != currentEdgeEffect) {
        if (mCurrentEdgeEffect == 0 || currentEdgeEffect != 0) {
            mCurrentEdgeEffect = currentEdgeEffect;
            mEdgeEffect.finish();
        }
        mEdgeEffect.setSize(getWidth(), mEdgeSize);
    }
    if (currentEdgeEffect != 0) {
        mEdgeEffect.onPull(mEdgeSize);
    }
}

From source file:com.linhnv.apps.maxim.utils.ImageWorker.java

private BitmapDrawable roundCornered(BitmapDrawable scaledBitmap, int i) {

    Bitmap bitmap = scaledBitmap.getBitmap();

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

    int color = 0xff424242;
    Paint paint = new Paint();
    Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    RectF rectF = new RectF(rect);
    int roundPx = i;
    paint.setAntiAlias(true);//from  ww  w  .j a v  a  2s. c o m
    canvas.drawARGB(0, 0, 0, 0);
    // paint.setColor(Color.BLUE);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    BitmapDrawable finalresult = new BitmapDrawable(mResources, result);
    return finalresult;
}

From source file:com.yk.notification.util.BitmapUtil.java

/**
 * ??//from  w  w w.  j a  va  2  s  .  c  om
 * 
 * @param bitmap
 *            Bitmap
 * @return Bitmap
 */
public static Bitmap getRoundBitmap(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    float roundPx;
    float left, top, right, bottom, dst_left, dst_top, dst_right, dst_bottom;
    if (width <= height) {
        roundPx = width / 2;
        top = 0;
        bottom = width;
        left = 0;
        right = width;
        height = width;
        dst_left = 0;
        dst_top = 0;
        dst_right = width;
        dst_bottom = width;
    } else {
        roundPx = height / 2;
        float clip = (width - height) / 2;
        left = clip;
        right = width - clip;
        top = 0;
        bottom = height;
        width = height;
        dst_left = 0;
        dst_top = 0;
        dst_right = height;
        dst_bottom = height;
    }

    Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect src = new Rect((int) left, (int) top, (int) right, (int) bottom);
    final Rect dst = new Rect((int) dst_left, (int) dst_top, (int) dst_right, (int) dst_bottom);
    final RectF rectF = new RectF(dst);

    paint.setAntiAlias(true);

    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, src, dst, paint);
    return output;
}

From source file:mil.nga.giat.mage.sdk.utils.MediaUtility.java

public static Bitmap resizeAndRoundCorners(Bitmap bitmap, int maxSize) {
    boolean isLandscape = bitmap.getWidth() > bitmap.getHeight();

    int newWidth, newHeight;
    if (isLandscape) {
        newWidth = maxSize;/*from w ww  . j  a  v  a 2s  .c  om*/
        newHeight = Math.round(((float) newWidth / bitmap.getWidth()) * bitmap.getHeight());
    } else {
        newHeight = maxSize;
        newWidth = Math.round(((float) newHeight / bitmap.getHeight()) * bitmap.getWidth());
    }

    Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, false);

    if (resizedBitmap != bitmap)
        bitmap.recycle();

    Bitmap roundedProfile = Bitmap.createBitmap(resizedBitmap.getWidth(), resizedBitmap.getHeight(),
            Config.ARGB_8888);

    Canvas roundedCanvas = new Canvas(roundedProfile);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, roundedProfile.getWidth(), roundedProfile.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = 7.0f;

    paint.setAntiAlias(true);
    roundedCanvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    roundedCanvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    roundedCanvas.drawBitmap(resizedBitmap, rect, rect, paint);
    return roundedProfile;
}

From source file:me.tb.player.SkeletonActivity.java

@Override
public Bitmap getCircleBitmap(Bitmap bitmap) {
    final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);

    final int color = Color.RED;
    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 ava  2s  . c om
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawOval(rectF, paint);

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

    bitmap.recycle();

    return output;
}

From source file:com.c4mprod.utils.ImageManager.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {

    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 = 20;

    paint.setAntiAlias(true);/*from ww w.j  a  v  a2  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);

    if (output != bitmap) {
        bitmap.recycle();
    }
    return output;
}