From 9cfab4bc18b8d9d905263c687e19c06df885dca7 Mon Sep 17 00:00:00 2001 From: Wu-cheng Li Date: Tue, 9 Nov 2010 22:00:27 +0800 Subject: Rotate the postview to correct orientation in video attach mode. Manual merge from gingerbread. bug:3208306 Change-Id: Ib7fb0a960c862527324adefd419e74224f59bc30 --- src/com/android/camera/Util.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/com/android/camera/Util.java') diff --git a/src/com/android/camera/Util.java b/src/com/android/camera/Util.java index 71d0c21..ac99956 100644 --- a/src/com/android/camera/Util.java +++ b/src/com/android/camera/Util.java @@ -54,10 +54,28 @@ public class Util { // Rotates the bitmap by the specified degree. // If a new bitmap is created, the original bitmap is recycled. public static Bitmap rotate(Bitmap b, int degrees) { - if (degrees != 0 && b != null) { + return rotateAndMirror(b, degrees, false); + } + + // Rotates and/or mirrors the bitmap. If a new bitmap is created, the + // original bitmap is recycled. + public static Bitmap rotateAndMirror(Bitmap b, int degrees, boolean mirror) { + if ((degrees != 0 || mirror) && b != null) { Matrix m = new Matrix(); m.setRotate(degrees, (float) b.getWidth() / 2, (float) b.getHeight() / 2); + if (mirror) { + m.postScale(-1, 1); + degrees = (degrees + 360) % 360; + if (degrees == 0 || degrees == 180) { + m.postTranslate((float) b.getWidth(), 0); + } else if (degrees == 90 || degrees == 270) { + m.postTranslate((float) b.getHeight(), 0); + } else { + throw new IllegalArgumentException("Invalid degrees=" + degrees); + } + } + try { Bitmap b2 = Bitmap.createBitmap( b, 0, 0, b.getWidth(), b.getHeight(), m, true); -- cgit v1.1