rk平台修改竖屏摄像头预览拉伸问题

rk平台修改竖屏摄像头预览拉伸问题

前提:
摄像头拍照的是4:3比例的图像,横屏预览正常,竖屏预览拉伸,调整竖屏预览的比例。

index 22f8a9c001..242b8c2d5a 100755
--- a/packages/apps/Camera2/src/com/android/camera/CaptureLayoutHelper.java
+++ b/packages/apps/Camera2/src/com/android/camera/CaptureLayoutHelper.java
@@ -24,6 +24,13 @@ import com.android.camera.app.CameraApp;
 import com.android.camera.app.CameraAppUI;
 import com.android.camera.ui.PreviewStatusListener;
 import com.android.camera2.R;
+import com.android.camera.util.CameraUtil;
+import com.android.camera.debug.DebugPropertyHelper;
+import com.android.camera.debug.Log;
+import com.android.camera.util.CameraUtil;
+import com.android.ex.camera2.portability.CameraDeviceInfo.Characteristics;
+import com.android.camera.settings.SettingsManager;
+import com.android.camera.settings.Keys;
 
 /**
  * This class centralizes the logic of how bottom bar should be laid out and how
@@ -42,6 +49,8 @@ public class CaptureLayoutHelper implements CameraAppUI.NonDecorWindowSizeChange
     private final int mBottomBarMinHeight;
     private final int mBottomBarMaxHeight;
     private final int mBottomBarOptimalHeight;
+	private static final Log.Tag TAG = new Log.Tag("CaptureLayoutHelper");
+	
 
     private int mWindowWidth = 0;
     private int mWindowHeight = 0;
@@ -236,6 +245,21 @@ public class CaptureLayoutHelper implements CameraAppUI.NonDecorWindowSizeChange
         if (mActivity != null && changed)
             mActivity.onNonDecorWindowSizeChanged();
     }
+	
+	
+       public static void fixUpPreviewRect(PositionConfiguration config,int width, int height)
+       {
+	   
+                //FIX UP THE PREVIEW SURFACE LAYOUT!
+               Matrix rotate = new Matrix();
+        rotate.setRotate(0, height/2 , width/2 );
+        rotate.mapRect(config.mPreviewRect);
+				android.util.Log.e("hwt ","height3  "+height+" width  "+width);
+               Matrix roundupMatrix = new Matrix();
+              roundupMatrix.setRectToRect(config.mPreviewRect,new RectF(0,0,width,height-500),Matrix.ScaleToFit.CENTER);
+               roundupMatrix.mapRect(config.mPreviewRect);
+               android.util.Log.d("DEBUG","FIX UP THE PREVIEW SURFACE LAYOUT!");
+       }
 
     /**
      * Calculates the layout rect of bottom bar and the size of preview based on
@@ -253,6 +277,19 @@ public class CaptureLayoutHelper implements CameraAppUI.NonDecorWindowSizeChange
     private PositionConfiguration getPositionConfiguration(int width, int height,
             float previewAspectRatio, int rotation) {
         boolean landscape = width > height;
+		
+		int displayRotaion = CameraUtil.getDisplayRotation();
+		int cameraheight = 0;
+         //previewAspectRatio=1.3333334f;
+			   
+		 int mDisplayRotation = CameraUtil.getDisplayRotation();
+       SettingsManager settingsManager = mActivity.getSettingsManager();
+       int mCameraId = settingsManager.getInteger(SettingsManager.SCOPE_GLOBAL,
+                                               Keys.KEY_CAMERA_ID);
+        Characteristics info =
+                mActivity.getCameraProvider().getCharacteristics(mCameraId);
+        int mDisplayOrientation = info.getPreviewOrientation(mDisplayRotation);
+       System.out.println("===hwt width="+width + " height="+height + " previewAspectRatio="+previewAspectRatio + " rotation="+rotation + " mDisplayOrientation="+mDisplayOrientation);
 
         // If the aspect ratio is defined as fill the screen, then preview should
         // take the screen rect.
@@ -293,8 +330,16 @@ public class CaptureLayoutHelper implements CameraAppUI.NonDecorWindowSizeChange
                     config.mBottomBarRect.set(width - barSize, height / 2 - previewShorterEdge / 2,
                             width, height / 2 + previewShorterEdge / 2);
                 } else {
-                    config.mPreviewRect.set(width / 2 - previewShorterEdge / 2, 0,
+                    //config.mPreviewRect.set(width / 2 - previewShorterEdge / 2, 0,
+                           // width / 2 + previewShorterEdge / 2, previewLongerEdge);
+				   if(mDisplayOrientation == 90 || mDisplayOrientation == 270){
+                       config.mPreviewRect.set(width / 2 - previewShorterEdge / 2, 0,
                             width / 2 + previewShorterEdge / 2, previewLongerEdge);
+                   }else{
+				   		android.util.Log.e("hwt","1");
+                       config.mPreviewRect.set(0, height / 2 - (width / previewAspectRatio) / 2-cameraheight,
+                            width, height / 2 + ((width / previewAspectRatio) / 2)+cameraheight);
+                   }
                     config.mBottomBarRect.set(width / 2 - previewShorterEdge / 2, height - barSize,
                             width / 2 + previewShorterEdge / 2, height);
                 }
@@ -313,8 +358,16 @@ public class CaptureLayoutHelper implements CameraAppUI.NonDecorWindowSizeChange
                     config.mBottomBarRect.set(width - barSize, 0, width, height);
                 } else {
                     float bottom = height;
-                    float top = bottom - previewLongerEdge;
-                    config.mPreviewRect.set(0, top, previewShorterEdge, bottom);
+                    float top = 0;
+					if(mDisplayOrientation == 90 || mDisplayOrientation == 270){
+                       config.mPreviewRect.set(0, top, previewShorterEdge, bottom);
+                   }else{
+				   android.util.Log.e("hwt","2");
+                       config.mPreviewRect.set(0, height / 2 - (width / previewAspectRatio) / 2-cameraheight,
+                            width, height / 2 + ((width / previewAspectRatio) / 2)+cameraheight);
+                   }
+					
+                    //config.mPreviewRect.set(0, top, previewShorterEdge, bottom);
                     config.mBottomBarRect.set(0, height - barSize, width, height);
                 }
             } else if (remainingSpaceAlongLongerEdge <= mBottomBarMinHeight) {
@@ -329,8 +382,17 @@ public class CaptureLayoutHelper implements CameraAppUI.NonDecorWindowSizeChange
                     config.mBottomBarRect.set(width - barSize, height / 2 - previewShorterEdge / 2,
                             width, height / 2 + previewShorterEdge / 2);
                 } else {
-                    config.mPreviewRect.set(width / 2 - previewShorterEdge / 2, 0,
-                            width / 2 + previewShorterEdge / 2, previewLongerEdge);
+                    //config.mPreviewRect.set(width / 2 - previewShorterEdge / 2, 0,
+                            //width / 2 + previewShorterEdge / 2, previewLongerEdge);
+					 if(mDisplayOrientation == 90 || mDisplayOrientation == 270){
+                       config.mPreviewRect.set(width / 2 - previewShorterEdge / 2, 0,
+                           width / 2 + previewShorterEdge / 2, previewLongerEdge);
+                   }else{
+				   android.util.Log.e("hwt","3");
+                       config.mPreviewRect.set(0, height / 2 - (width / previewAspectRatio) / 2-cameraheight,
+                            width, height / 2 + ((width / previewAspectRatio) / 2)+cameraheight);
+                   }		
+						
                     config.mBottomBarRect.set(width / 2 - previewShorterEdge / 2, height - barSize,
                             width / 2 + previewShorterEdge / 2, height);
                 }
@@ -348,8 +410,15 @@ public class CaptureLayoutHelper implements CameraAppUI.NonDecorWindowSizeChange
                     config.mBottomBarRect.set(width - barSize, 0, width, height);
                 } else {
                     float bottom = height - barSize;
-                    float top = bottom - previewLongerEdge;
-                    config.mPreviewRect.set(0, top, previewShorterEdge, bottom);
+                    float top = 0;
+				   if(mDisplayOrientation == 90 || mDisplayOrientation == 270){
+                       config.mPreviewRect.set(0, top, previewShorterEdge, bottom);
+                   }else{
+				   		android.util.Log.e("hwt","4");
+                       config.mPreviewRect.set(0, height / 2 - (width / previewAspectRatio) / 2-cameraheight,
+                            width, height / 2 + ((width / previewAspectRatio) / 2)+cameraheight);
+                   }
+                    //config.mPreviewRect.set(0, top, previewShorterEdge, bottom);
                     config.mBottomBarRect.set(0, height - barSize, width, height);
                 }
             }
@@ -364,6 +433,11 @@ public class CaptureLayoutHelper implements CameraAppUI.NonDecorWindowSizeChange
 //            rotate.mapRect(config.mBottomBarRect);
 //        }
 
+			if((displayRotaion==0||displayRotaion==180)!=landscape)
+               {
+                    //fixUpPreviewRect(config,width,height);
+               }
+
         // Round the rect first to avoid rounding errors later on.
         round(config.mBottomBarRect);
         round(config.mPreviewRect);
diff --git a/packages/apps/Camera2/src/com/android/camera/CaptureModule.java b/packages/apps/Camera2/src/com/android/camera/CaptureModule.java
index 93cf9075b3..435511437a 100755
--- a/packages/apps/Camera2/src/com/android/camera/CaptureModule.java
+++ b/packages/apps/Camera2/src/com/android/camera/CaptureModule.java
@@ -122,8 +122,9 @@ public class CaptureModule extends CameraModule implements
     private static final Tag TAG = new Tag("CaptureModule");
     /** Enable additional debug output. */
     private static final boolean DEBUG = true;
+	
     /** Workaround Flag for b/19271661 to use autotransformation in Capture Layout in Nexus4 **/
-    private static final boolean USE_AUTOTRANSFORM_UI_LAYOUT = ApiHelper.IS_NEXUS_4;
+    private static final boolean USE_AUTOTRANSFORM_UI_LAYOUT = true;
 
     /** Timeout for camera open/close operations. */
     private static final int CAMERA_OPEN_CLOSE_TIMEOUT_MILLIS = 2500;
@@ -692,6 +693,7 @@ public class CaptureModule extends CameraModule implements
     private void updatePreviewBufferSize() {
         synchronized (mSurfaceTextureLock) {
             if (mPreviewSurfaceTexture != null) {
+				Log.e(TAG," hwt mPreviewBufferWidth "+mPreviewBufferWidth+" mPreviewBufferHeight "+mPreviewBufferHeight);
                 mPreviewSurfaceTexture.setDefaultBufferSize(mPreviewBufferWidth,
                         mPreviewBufferHeight);
             }
在这里插入代码片
  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值