From 655afcf4a88cf9dcdbab708212df1dec0a4c05d6 Mon Sep 17 00:00:00 2001 From: nicolasroard Date: Tue, 27 Aug 2013 18:01:16 -0700 Subject: Fix param border needed to replace bitmap borders bug:9470514 Change-Id: I69f6324246ee8c9491ec430c5e20d87574302fcf --- .../filtershow/filters/ImageFilterColorBorder.java | 42 ++++++++++++++-------- 1 file changed, 27 insertions(+), 15 deletions(-) (limited to 'src/com/android/gallery3d/filtershow/filters/ImageFilterColorBorder.java') diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterColorBorder.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterColorBorder.java index 26f74a2a3..5cc7c3da6 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterColorBorder.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterColorBorder.java @@ -19,26 +19,24 @@ package com.android.gallery3d.filtershow.filters; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; -import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Path; import android.graphics.RectF; -import com.android.gallery3d.app.Log; - public class ImageFilterColorBorder extends ImageFilter { private static final String LOGTAG = "ImageFilterColorBorder"; private FilterColorBorderRepresentation mParameters = null; Paint mPaint = new Paint(); - RectF mRect = new RectF(); + RectF mBounds = new RectF(); + RectF mInsideBounds = new RectF(); + Path mBorderPath = new Path(); public ImageFilterColorBorder() { mName = "Border"; - mPaint.setStyle(Paint.Style.STROKE); } public FilterRepresentation getDefaultRepresentation() { - return new FilterColorBorderRepresentation(Color.WHITE, 4, 4); + return new FilterColorBorderRepresentation(Color.WHITE, 3, 2); } public void useRepresentation(FilterRepresentation representation) { @@ -55,17 +53,31 @@ public class ImageFilterColorBorder extends ImageFilter { if (getParameters() == null) { return; } - mRect.set(0, 0, w, h); - mPaint.setColor(getParameters().getColor()); float size = getParameters().getBorderSize(); float radius = getParameters().getBorderRadius(); - Matrix m = getOriginalToScreenMatrix(w, h); - radius = m.mapRadius(radius); - size = m.mapRadius(size); - mPaint.setStrokeWidth(size); - canvas.drawRoundRect(mRect, radius, radius, mPaint); - mRect.set(0 - radius, -radius, w + radius, h + radius); - canvas.drawRoundRect(mRect, 0, 0, mPaint); + + mPaint.reset(); + mPaint.setColor(getParameters().getColor()); + mPaint.setAntiAlias(true); + mBounds.set(0, 0, w, h); + mBorderPath.reset(); + mBorderPath.moveTo(0, 0); + + float bs = size / 100.f * mBounds.width(); + float r = radius / 100.f * mBounds.width(); + + mInsideBounds.set(mBounds.left + bs, + mBounds.top + bs, mBounds.right - bs, + mBounds.bottom - bs); + + mBorderPath.moveTo(mBounds.left, mBounds.top); + mBorderPath.lineTo(mBounds.right, mBounds.top); + mBorderPath.lineTo(mBounds.right, mBounds.bottom); + mBorderPath.lineTo(mBounds.left, mBounds.bottom); + mBorderPath.addRoundRect(mInsideBounds, + r, r, Path.Direction.CCW); + + canvas.drawPath(mBorderPath, mPaint); } @Override -- cgit v1.2.3