diff options
Diffstat (limited to 'src/com/android/gallery3d/filtershow/imageshow')
3 files changed, 50 insertions, 5 deletions
diff --git a/src/com/android/gallery3d/filtershow/imageshow/GeometryMath.java b/src/com/android/gallery3d/filtershow/imageshow/GeometryMath.java index 33a3f73cb..55f791820 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/GeometryMath.java +++ b/src/com/android/gallery3d/filtershow/imageshow/GeometryMath.java @@ -16,6 +16,7 @@ package com.android.gallery3d.filtershow.imageshow; +import android.graphics.Rect; import android.graphics.RectF; public class GeometryMath { @@ -99,4 +100,10 @@ public class GeometryMath { return Math.min(newWidth / oldWidth , newHeight / oldHeight); } + public static Rect roundNearest(RectF r){ + Rect q = new Rect(Math.round(r.left), Math.round(r.top), Math.round(r.right), + Math.round(r.bottom)); + return q; + } + } diff --git a/src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java b/src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java index cf52b15ca..dffdc2449 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java +++ b/src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java @@ -59,10 +59,8 @@ public class GeometryMetadata { if (mStraightenRotation != 0) { return true; } - Rect cropBounds = new Rect(); - mCropBounds.roundOut(cropBounds); - Rect photoBounds = new Rect(); - mPhotoBounds.roundOut(photoBounds); + Rect cropBounds = GeometryMath.roundNearest(mCropBounds); + Rect photoBounds = GeometryMath.roundNearest(mPhotoBounds); if (!cropBounds.equals(photoBounds)) { return true; } diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageCrop.java b/src/com/android/gallery3d/filtershow/imageshow/ImageCrop.java index 35e8ad4b7..a352a16e7 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/ImageCrop.java +++ b/src/com/android/gallery3d/filtershow/imageshow/ImageCrop.java @@ -62,6 +62,17 @@ public class ImageCrop extends ImageGeometry { private static final String LOGTAG = "ImageCrop"; + private String mAspect = ""; + private int mAspectTextSize = 24; + + public void setAspectTextSize(int textSize){ + mAspectTextSize = textSize; + } + + public void setAspectString(String a){ + mAspect = a; + } + private static final Paint gPaint = new Paint(); public ImageCrop(Context context) { @@ -581,7 +592,7 @@ public class ImageCrop extends ImageGeometry { public void imageLoaded() { super.imageLoaded(); syncLocalToMasterGeometry(); - applyOriginal(); + applyClear(); invalidate(); } @@ -642,6 +653,35 @@ public class ImageCrop extends ImageGeometry { gPaint.setStyle(Paint.Style.STROKE); drawRuleOfThird(canvas, crop, gPaint); + if (mFixAspectRatio){ + float w = crop.width(); + float h = crop.height(); + float diag = (float) Math.sqrt(w*w + h*h); + + float dash_len = 20; + int num_intervals = (int) (diag / dash_len); + float [] tl = { crop.left, crop.top }; + float centX = tl[0] + w/2; + float centY = tl[1] + h/2 + 5; + float [] br = { crop.right, crop.bottom }; + float [] vec = GeometryMath.getUnitVectorFromPoints(tl, br); + + float [] counter = tl; + for (int x = 0; x < num_intervals; x++ ){ + float tempX = counter[0] + vec[0] * dash_len; + float tempY = counter[1] + vec[1] * dash_len; + if ((x % 2) == 0 && Math.abs(x - num_intervals / 2) > 2){ + canvas.drawLine(counter[0], counter[1], tempX, tempY, gPaint); + } + counter[0] = tempX; + counter[1] = tempY; + } + + gPaint.setTextAlign(Paint.Align.CENTER); + gPaint.setTextSize(mAspectTextSize); + canvas.drawText(mAspect, centX, centY, gPaint); + } + gPaint.setColor(mBorderColor); gPaint.setStrokeWidth(3); gPaint.setStyle(Paint.Style.STROKE); |