diff options
author | John Hoford <hoford@google.com> | 2013-08-22 14:38:19 -0700 |
---|---|---|
committer | John Hoford <hoford@google.com> | 2013-08-22 15:22:18 -0700 |
commit | 49798939f1bc58eaf5842bbc8bc5424284ab7930 (patch) | |
tree | 1c46853c45ce2ad7f5a930b29c779f4365ec4028 /src/com/android/gallery3d/filtershow/filters/ImageFilterColorBorder.java | |
parent | 73d0f42972c7c49a2589f2184f67e5a887007e7e (diff) | |
download | android_packages_apps_Gallery2-49798939f1bc58eaf5842bbc8bc5424284ab7930.tar.gz android_packages_apps_Gallery2-49798939f1bc58eaf5842bbc8bc5424284ab7930.tar.bz2 android_packages_apps_Gallery2-49798939f1bc58eaf5842bbc8bc5424284ab7930.zip |
border UI editor
bug:9470514
Change-Id: I4d5cd91775c9b8742f847fd9a955f6f28e66cd38
Diffstat (limited to 'src/com/android/gallery3d/filtershow/filters/ImageFilterColorBorder.java')
-rw-r--r-- | src/com/android/gallery3d/filtershow/filters/ImageFilterColorBorder.java | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterColorBorder.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterColorBorder.java new file mode 100644 index 000000000..26f74a2a3 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterColorBorder.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +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(); + + public ImageFilterColorBorder() { + mName = "Border"; + mPaint.setStyle(Paint.Style.STROKE); + } + + public FilterRepresentation getDefaultRepresentation() { + return new FilterColorBorderRepresentation(Color.WHITE, 4, 4); + } + + public void useRepresentation(FilterRepresentation representation) { + FilterColorBorderRepresentation parameters = + (FilterColorBorderRepresentation) representation; + mParameters = parameters; + } + + public FilterColorBorderRepresentation getParameters() { + return mParameters; + } + + private void applyHelper(Canvas canvas, int w, int h) { + 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); + } + + @Override + public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) { + Canvas canvas = new Canvas(bitmap); + applyHelper(canvas, bitmap.getWidth(), bitmap.getHeight()); + return bitmap; + } + +} |