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.almalence.googsharing.Thumbnail.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int size, int pixels) {
    final int side = Math.min(bitmap.getWidth(), bitmap.getHeight());

    final Bitmap bitmapCropped = Bitmap.createBitmap(bitmap, (bitmap.getWidth() - side) / 2,
            (bitmap.getHeight() - side) / 2, side, side);

    final Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(output);

    final int color = 0xffffffff;
    final Paint paint = new Paint();
    final Rect rectSrc = new Rect(0, 0, bitmapCropped.getWidth(), bitmapCropped.getHeight());
    final Rect rect = new Rect(6, 6, output.getWidth() - 6, output.getHeight() - 6);
    final RectF rectF = new RectF(rect);
    final RectF rectFBorder = new RectF(0, 0, output.getWidth(), output.getHeight());
    final float roundPx = pixels;

    paint.setAntiAlias(true);//  w  ww  . 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(bitmapCropped, rectSrc, rect, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.DST_ATOP));
    canvas.drawRoundRect(rectFBorder, roundPx, roundPx, paint);

    return output;
}

From source file:org.stockchart.core.Appearance.java

public void applyFill(Paint p, Rect rect) {
    this.applyFill(p, new RectF(rect));
}

From source file:net.networksaremadeofstring.rhybudd.ZenossWidgetGraph.java

private Bitmap RenderBarGraph(int CritCount, int ErrCount, int WarnCount) {

    //Log.i("Counts", Integer.toString(CritCount) + " / " + Integer.toString(ErrCount) + " / " + Integer.toString(WarnCount));
    Bitmap emptyBmap = Bitmap.createBitmap(290, 150, Config.ARGB_8888);

    int width = emptyBmap.getWidth();
    int height = emptyBmap.getHeight();
    Bitmap charty = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(charty);
    //final int color = 0xff0B0B61; 
    final Paint paint = new Paint();

    paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.WHITE);//  w w  w . j  a  va 2 s.  c  om

    //y
    canvas.drawLine(25, 0, 25, 289, paint);
    //x
    canvas.drawLine(25, 149, 289, 149, paint);

    paint.setAntiAlias(true);
    int Max = 0;

    if (CritCount > ErrCount && CritCount > WarnCount)
        Max = CritCount;
    else if (ErrCount > CritCount && ErrCount > WarnCount)
        Max = ErrCount;
    else if (WarnCount > CritCount && WarnCount > ErrCount)
        Max = WarnCount;
    else
        Max = CritCount;

    if (Max > 0)
        canvas.drawText(Integer.toString(Max), 0, 10, paint);

    if (Max > 1)
        canvas.drawText(Integer.toString(Max / 2), 0, 75, paint);

    canvas.drawText("0", 0, 148, paint);

    double divisor = 148 / (double) Max;

    paint.setAlpha(128);

    Rect rect = new Rect(32, (int) (148 - (divisor * CritCount)), 64, 148);
    paint.setColor(Color.argb(200, 208, 0, 0)); //red

    if (CritCount > 0)
        canvas.drawRect(new RectF(rect), paint);

    rect = new Rect(128, (int) (148 - (divisor * ErrCount)), 160, 148);
    paint.setColor(Color.argb(200, 255, 102, 0));//orange

    if (ErrCount > 0)
        canvas.drawRect(new RectF(rect), paint);

    rect = new Rect(224, (int) (148 - (divisor * WarnCount)), 256, 148);
    paint.setColor(Color.argb(200, 255, 224, 57)); //yellow
    if (WarnCount > 0)
        canvas.drawRect(new RectF(rect), paint);

    //Return
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    charty.compress(CompressFormat.PNG, 50, out);

    return BitmapFactory.decodeByteArray(out.toByteArray(), 0, out.size());
}

From source file:org.jared.synodroid.ds.utils.Utils.java

/**
 * Create a rounded bitmap//from  w  w w  .j  ava 2  s .c  o  m
 * 
 * @param bitmap
 *            The original bitmap
 * @return
 */
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.example.linhdq.test.documents.creation.crop.CropImageActivity.java

@OnClick(R.id.item_save)
void onSaveClicked() {
    if (!mCropData.isPresent() || mSaving || (mCrop == null)) {
        return;//from  ww  w.  j a va 2 s . c o  m
    }
    mSaving = true;

    Util.startBackgroundJob(this, null, getText(R.string.cropping_image).toString(), new Runnable() {
        public void run() {
            try {
                float scale = 1f / mCropData.get().getScaleResult().getScaleFactor();
                Matrix scaleMatrix = new Matrix();
                scaleMatrix.setScale(scale, scale);

                final float[] trapezoid = mCrop.getTrapezoid();
                final RectF perspectiveCorrectedBoundingRect = new RectF(
                        mCrop.getPerspectiveCorrectedBoundingRect());
                scaleMatrix.mapRect(perspectiveCorrectedBoundingRect);
                Box bb = new Box((int) perspectiveCorrectedBoundingRect.left,
                        (int) perspectiveCorrectedBoundingRect.top,
                        (int) perspectiveCorrectedBoundingRect.width(),
                        (int) perspectiveCorrectedBoundingRect.height());

                Pix pix8 = Convert.convertTo8(mPix);
                mPix.recycle();

                Pix croppedPix = Clip.clipRectangle2(pix8, bb);
                if (croppedPix == null) {
                    throw new IllegalStateException();
                }
                pix8.recycle();

                scaleMatrix.postTranslate(-bb.getX(), -bb.getY());
                scaleMatrix.mapPoints(trapezoid);

                final float[] dest = new float[] { 0, 0, bb.getWidth(), 0, bb.getWidth(), bb.getHeight(), 0,
                        bb.getHeight() };
                Pix bilinear = Projective.projectiveTransform(croppedPix, dest, trapezoid);
                if (bilinear == null) {
                    bilinear = croppedPix;
                } else {
                    croppedPix.recycle();
                }

                if (mRotation != 0 && mRotation != 4) {
                    Pix rotatedPix = Rotate.rotateOrth(bilinear, mRotation);
                    bilinear.recycle();
                    bilinear = rotatedPix;
                }
                if (bilinear == null) {
                    throw new IllegalStateException();
                }
                Intent result = new Intent();
                OCR.savePixToCacheDir(CropImageActivity.this, bilinear.copy());
                result.putExtra(DocumentGridActivity.EXTRA_NATIVE_PIX, bilinear.getNativePix());
                setResult(RESULT_OK, result);
            } catch (IllegalStateException e) {
                setResult(RESULT_CANCELED);
            } finally {
                finish();
            }
        }
    }, mHandler);

}

From source file:com.android.camera.HighlightView.java

private void growBy(float dx, float dy) {
    if (mMaintainAspectRatio) {
        if (dx != 0) {
            dy = dx / mInitialAspectRatio;
        } else if (dy != 0) {
            dx = dy * mInitialAspectRatio;
        }//from  w  w  w  . j  a va 2 s.co m
    }

    // Don't let the cropping rectangle grow too fast.
    // Grow at most half of the difference between the image rectangle and
    // the cropping rectangle.
    RectF r = new RectF(mCropRect);
    if (dx > 0F && r.width() + 2 * dx > mImageRect.width()) {
        dx = (mImageRect.width() - r.width()) / 2F;
        if (mMaintainAspectRatio) {
            dy = dx / mInitialAspectRatio;
        }
    }
    if (dy > 0F && r.height() + 2 * dy > mImageRect.height()) {
        dy = (mImageRect.height() - r.height()) / 2F;
        if (mMaintainAspectRatio) {
            dx = dy * mInitialAspectRatio;
        }
    }

    r.inset(-dx, -dy);

    // Don't let the cropping rectangle shrink too fast.
    final float widthCap = 25F;
    if (r.width() < widthCap) {
        r.inset(-(widthCap - r.width()) / 2F, 0F);
    }
    float heightCap = mMaintainAspectRatio ? (widthCap / mInitialAspectRatio) : widthCap;
    if (r.height() < heightCap) {
        r.inset(0F, -(heightCap - r.height()) / 2F);
    }

    // Put the cropping rectangle inside the image rectangle.
    if (r.left < mImageRect.left) {
        r.offset(mImageRect.left - r.left, 0F);
    } else if (r.right > mImageRect.right) {
        r.offset(-(r.right - mImageRect.right), 0);
    }
    if (r.top < mImageRect.top) {
        r.offset(0F, mImageRect.top - r.top);
    } else if (r.bottom > mImageRect.bottom) {
        r.offset(0F, -(r.bottom - mImageRect.bottom));
    }

    mCropRect.set(r);
    mDrawRect = computeLayout();
    mContext.invalidate();
}

From source file:com.example.gatsu.theevent.HighlightView.java

void growBy(float dx, float dy) {

    if (mMaintainAspectRatio) {
        if (dx != 0) {
            dy = dx / mInitialAspectRatio;
        } else if (dy != 0) {
            dx = dy * mInitialAspectRatio;
        }// w  ww  . j ava 2 s  .  co m
    }

    // Don't let the cropping rectangle grow too fast.
    // Grow at most half of the difference between the image rectangle and
    // the cropping rectangle.
    RectF r = new RectF(mCropRect);
    if (dx > 0F && r.width() + 2 * dx > mImageRect.width()) {
        float adjustment = (mImageRect.width() - r.width()) / 2F;
        dx = adjustment;
        if (mMaintainAspectRatio) {
            dy = dx / mInitialAspectRatio;
        }
    }
    if (dy > 0F && r.height() + 2 * dy > mImageRect.height()) {
        float adjustment = (mImageRect.height() - r.height()) / 2F;
        dy = adjustment;
        if (mMaintainAspectRatio) {
            dx = dy * mInitialAspectRatio;
        }
    }

    r.inset(-dx, -dy);

    // Don't let the cropping rectangle shrink too fast.
    final float widthCap = 25F;
    if (r.width() < widthCap) {
        r.inset(-(widthCap - r.width()) / 2F, 0F);
    }
    float heightCap = mMaintainAspectRatio ? (widthCap / mInitialAspectRatio) : widthCap;
    if (r.height() < heightCap) {
        r.inset(0F, -(heightCap - r.height()) / 2F);
    }

    // Put the cropping rectangle inside the image rectangle.
    if (r.left < mImageRect.left) {
        r.offset(mImageRect.left - r.left, 0F);
    } else if (r.right > mImageRect.right) {
        r.offset(-(r.right - mImageRect.right), 0);
    }
    if (r.top < mImageRect.top) {
        r.offset(0F, mImageRect.top - r.top);
    } else if (r.bottom > mImageRect.bottom) {
        r.offset(0F, -(r.bottom - mImageRect.bottom));
    }

    mCropRect.set(r);
    mDrawRect = computeLayout();
    mContext.invalidate();
}

From source file:org.caojun.library.cropimage.HighlightView.java

void growBy(float dx, float dy) {

    if (mMaintainAspectRatio) {
        if (dx != 0) {
            dy = dx / mInitialAspectRatio;
        } else if (dy != 0) {
            dx = dy * mInitialAspectRatio;
        }//from   ww w .  ja  v  a2 s .com
    }

    // Don't let the cropping rectangle grow too fast.
    // Grow at most half of the difference between the image rectangle and
    // the cropping rectangle.
    RectF r = new RectF(mCropRect);
    if (dx > 0F && r.width() + 2 * dx > mImageRect.width()) {
        float adjustment = (mImageRect.width() - r.width()) / 2F;
        dx = adjustment;
        if (mMaintainAspectRatio) {
            dy = dx / mInitialAspectRatio;
        }
    }
    if (dy > 0F && r.height() + 2 * dy > mImageRect.height()) {
        float adjustment = (mImageRect.height() - r.height()) / 2F;
        dy = adjustment;
        if (mMaintainAspectRatio) {
            dx = dy * mInitialAspectRatio;
        }
    }

    r.inset(-dx, -dy);

    // Don't let the cropping rectangle shrink too fast.
    final float widthCap = 25F;
    if (r.width() < widthCap) {
        r.inset(-(widthCap - r.width()) / 2F, 0F);
    }
    float heightCap = mMaintainAspectRatio ? (widthCap / mInitialAspectRatio) : widthCap;
    if (r.height() < heightCap) {
        r.inset(0F, -(heightCap - r.height()) / 2F);
    }

    // Put the cropping rectangle inside the image rectangle.
    if (r.left < mImageRect.left) {
        r.offset(mImageRect.left - r.left, 0F);
    } else if (r.right > mImageRect.right) {
        r.offset(-(r.right - mImageRect.right), 0);
    }
    if (r.top < mImageRect.top) {
        r.offset(0F, mImageRect.top - r.top);
    } else if (r.bottom > mImageRect.bottom) {
        r.offset(0F, -(r.bottom - mImageRect.bottom));
    }

    mCropRect.set(r);
    mDrawRect = computeLayout();
    mView.invalidate();
}

From source file:com.android.camera.HighlightView.java

public void setup(Matrix m, Rect imageRect, RectF cropRect, boolean circle, boolean maintainAspectRatio) {
    if (circle) {
        maintainAspectRatio = true;/*from   w  w w .  j  av  a  2s .  c  om*/
    }
    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.android.mms.ui.MessageUtils.java

public static Bitmap getCircularBitmap(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 = bitmap.getWidth() / 2;

    paint.setAntiAlias(true);//from ww w.java  2s. 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;
}