Search in sources :

Example 86 with RectF

use of android.graphics.RectF in project WordPress-Android by wordpress-mobile.

the class ImageUtils method getRoundedEdgeBitmap.

/**
     * Returns the passed bitmap with rounded corners
     * @param bitmap - the bitmap to modify
     * @param radius - the radius of the corners
     * @param borderColor - the border to apply (use Color.TRANSPARENT for none)
     */
public static Bitmap getRoundedEdgeBitmap(final Bitmap bitmap, int radius, int borderColor) {
    if (bitmap == null) {
        return null;
    }
    final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    final 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);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.RED);
    canvas.drawRoundRect(rectF, radius, radius, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    if (borderColor != Color.TRANSPARENT) {
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(1f);
        paint.setColor(borderColor);
        canvas.drawRoundRect(rectF, radius, radius, paint);
    }
    return output;
}
Also used : RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint)

Example 87 with RectF

use of android.graphics.RectF in project ZI by yixia.

the class HighlightView method growBy.

// Grows the cropping rectange by (dx, dy) in image space.
void growBy(float dx, float dy) {
    if (mMaintainAspectRatio) {
        if (dx != 0) {
            dy = dx / mInitialAspectRatio;
        } else if (dy != 0) {
            dx = dy * mInitialAspectRatio;
        }
    }
    // 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();
}
Also used : RectF(android.graphics.RectF)

Example 88 with RectF

use of android.graphics.RectF in project ZI by yixia.

the class HighlightView method setup.

public void setup(Matrix m, Rect imageRect, RectF cropRect, boolean circle, boolean maintainAspectRatio) {
    if (circle) {
        maintainAspectRatio = true;
    }
    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();
}
Also used : RectF(android.graphics.RectF) Matrix(android.graphics.Matrix)

Example 89 with RectF

use of android.graphics.RectF in project ZI by yixia.

the class ImageViewTouchBase method center.

// Center as much as possible in one or both axis.  Centering is
// defined as follows:  if the image is scaled down below the
// view's dimensions then center it (literally).  If the image
// is scaled larger than the view and is translated out of view
// then translate it back into view (i.e. eliminate black bars).
protected void center(boolean horizontal, boolean vertical) {
    if (mBitmapDisplayed.getBitmap() == null) {
        return;
    }
    Matrix m = getImageViewMatrix();
    RectF rect = new RectF(0, 0, mBitmapDisplayed.getBitmap().getWidth(), mBitmapDisplayed.getBitmap().getHeight());
    m.mapRect(rect);
    float height = rect.height();
    float width = rect.width();
    float deltaX = 0, deltaY = 0;
    if (vertical) {
        int viewHeight = getHeight();
        if (height < viewHeight) {
            deltaY = (viewHeight - height) / 2 - rect.top;
        } else if (rect.top > 0) {
            deltaY = -rect.top;
        } else if (rect.bottom < viewHeight) {
            deltaY = getHeight() - rect.bottom;
        }
    }
    if (horizontal) {
        int viewWidth = getWidth();
        if (width < viewWidth) {
            deltaX = (viewWidth - width) / 2 - rect.left;
        } else if (rect.left > 0) {
            deltaX = -rect.left;
        } else if (rect.right < viewWidth) {
            deltaX = viewWidth - rect.right;
        }
    }
    postTranslate(deltaX, deltaY);
    setImageMatrix(getImageViewMatrix());
}
Also used : RectF(android.graphics.RectF) Matrix(android.graphics.Matrix)

Example 90 with RectF

use of android.graphics.RectF in project ZI by yixia.

the class ColorPickerView method drawAlphaPanel.

private void drawAlphaPanel(Canvas canvas) {
    if (!mShowAlphaPanel || mAlphaRect == null || mAlphaPattern == null)
        return;
    final RectF rect = mAlphaRect;
    if (BORDER_WIDTH_PX > 0) {
        mBorderPaint.setColor(mBorderColor);
        canvas.drawRect(rect.left - BORDER_WIDTH_PX, rect.top - BORDER_WIDTH_PX, rect.right + BORDER_WIDTH_PX, rect.bottom + BORDER_WIDTH_PX, mBorderPaint);
    }
    mAlphaPattern.draw(canvas);
    float[] hsv = new float[] { mHue, mSat, mVal };
    int color = Color.HSVToColor(hsv);
    int acolor = Color.HSVToColor(0, hsv);
    mAlphaShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top, color, acolor, TileMode.CLAMP);
    mAlphaPaint.setShader(mAlphaShader);
    canvas.drawRect(rect, mAlphaPaint);
    if (mAlphaSliderText != null && mAlphaSliderText != "") {
        canvas.drawText(mAlphaSliderText, rect.centerX(), rect.centerY() + 4 * mDensity, mAlphaTextPaint);
    }
    float rectWidth = 4 * mDensity / 2;
    Point p = alphaToPoint(mAlpha);
    RectF r = new RectF();
    r.left = p.x - rectWidth;
    r.right = p.x + rectWidth;
    r.top = rect.top - RECTANGLE_TRACKER_OFFSET;
    r.bottom = rect.bottom + RECTANGLE_TRACKER_OFFSET;
    canvas.drawRoundRect(r, 2, 2, mHueTrackerPaint);
}
Also used : RectF(android.graphics.RectF) LinearGradient(android.graphics.LinearGradient) Point(android.graphics.Point) Point(android.graphics.Point) Paint(android.graphics.Paint)

Aggregations

RectF (android.graphics.RectF)1274 Paint (android.graphics.Paint)451 Rect (android.graphics.Rect)178 Matrix (android.graphics.Matrix)155 Bitmap (android.graphics.Bitmap)150 Path (android.graphics.Path)141 Canvas (android.graphics.Canvas)136 Point (android.graphics.Point)86 ImageView (android.widget.ImageView)78 PorterDuffXfermode (android.graphics.PorterDuffXfermode)51 LinearGradient (android.graphics.LinearGradient)41 View (android.view.View)39 SuppressLint (android.annotation.SuppressLint)35 Drawable (android.graphics.drawable.Drawable)27 PointF (android.graphics.PointF)23 RadialGradient (android.graphics.RadialGradient)21 TextPaint (android.text.TextPaint)21 ArrayList (java.util.ArrayList)21 BitmapDrawable (android.graphics.drawable.BitmapDrawable)20 TypedArray (android.content.res.TypedArray)14