Permalink
Browse files

am d56274a: Rotate the postview to correct orientation in video attac…

…h mode. do not merge

* commit 'd56274ad69e088a1682d33c6d414261ed080b378':
  Rotate the postview to correct orientation in video attach mode. do not merge
  • Loading branch information...
Wu-cheng Li Android Git Automerger
Wu-cheng Li authored and Android Git Automerger committed Nov 10, 2010
2 parents 86b149d + d56274a commit 94170473a4b20a2e8d8072991debab10ae891a96
Showing with 31 additions and 3 deletions.
  1. +18 −0 src/com/android/camera/Util.java
  2. +13 −3 src/com/android/camera/VideoCamera.java
@@ -52,10 +52,28 @@ private 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) {
+ 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 && 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);
@@ -185,6 +185,7 @@
private int mOrientation = OrientationEventListener.ORIENTATION_UNKNOWN;
// The orientation compensation for icons and thumbnails.
private int mOrientationCompensation = 0;
+ private int mOrientationHint; // the orientation hint for video playback
// This Handler is used to post message back onto the main thread of the
// application
@@ -1005,6 +1006,7 @@ private void initializeRecorder() {
}
}
mMediaRecorder.setOrientationHint(rotation);
+ mOrientationHint = rotation;
try {
mMediaRecorder.prepare();
@@ -1262,9 +1264,17 @@ private void stopVideoRecordingAndShowAlert() {
private void showAlert() {
fadeOut(findViewById(R.id.shutter_button));
if (mCurrentVideoFilename != null) {
- mVideoFrame.setImageBitmap(
- ThumbnailUtils.createVideoThumbnail(mCurrentVideoFilename,
- Video.Thumbnails.MINI_KIND));
+ Bitmap src = ThumbnailUtils.createVideoThumbnail(
+ mCurrentVideoFilename, Video.Thumbnails.MINI_KIND);
+ // MetadataRetriever already rotates the thumbnail. We should rotate
+ // it back (and mirror if it is front-facing camera).
+ CameraInfo[] info = CameraHolder.instance().getCameraInfo();
+ if (info[mCameraId].facing == CameraInfo.CAMERA_FACING_BACK) {
+ src = Util.rotateAndMirror(src, -mOrientationHint, false);
+ } else {
+ src = Util.rotateAndMirror(src, -mOrientationHint, true);
+ }
+ mVideoFrame.setImageBitmap(src);
mVideoFrame.setVisibility(View.VISIBLE);
}
int[] pickIds = {R.id.btn_retake, R.id.btn_done, R.id.btn_play};

0 comments on commit 9417047

Please sign in to comment.