2012-11-03 174 views
2

我開發了一款基於相機的應用程序。它運行良好,但與Android 4.0相機和索尼Xperia Sola OS有一個問題。Android中的相機預覽

問題是以下幾點:

當我從我的應用程序相機預覽啓動相機顯示半屏索尼XPERIA索拉設備和其他設備HTC,三星就在全屏工作不錯。

對於相機預覽我用SurfaceView類。而在SurfaceChanged()方法我用下面的代碼

Parameters parameters = mCamera.getParameters(); 
Display display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); 

    if(display.getRotation() == Surface.ROTATION_0) 
    { 

     System.out.println("Preview Height : " + h); 
     System.out.println("Preview Width : " + w); 

     parameters.setPreviewSize(h, w);       
     mCamera.setDisplayOrientation(90); 
    } 

請幫我找到一個解決方案。

+0

我對這個解決方案可以在[http://stackoverflow.com/questions/13428797找到/camera-camera-preview-is-not-proper-after-setdisplayorientation-in-android](http://stackoverflow.com/questions/13428797/camera-camera-preview-is-not-proper-after-setdisplayorientation-在-機器人)。 –

回答

0

我很好奇,當你運行你的應用程序是什麼高度和寬度的打印輸出提供。我實現了一個簡單的SurfaceView類並使用你的代碼。的寬度和高度通過的logcat報道是

I /的System.out(4706):預覽寬度:480

I /的System.out(4706):預覽高度:744

這與SurfaceView跨越的區域相當一致。

小組代碼,我用這個:

public class Panel extends SurfaceView implements SurfaceHolder.Callback { 
    private Camera mCamera; 
    private Context mContext; 

    public Panel(Context context) { 
     super(context); 
     mContext = context; 
     getHolder().addCallback(this); 
    } 

    @Override 
    public void surfaceCreated(SurfaceHolder holder) { 
     try { 
      mCamera = Camera.open(); 
      mCamera.setPreviewDisplay(getHolder()); 
     } catch (IOException ioe) { 
      ioe.printStackTrace(); 
     } 

    } 

    @Override 
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { 
     Parameters parameters = mCamera.getParameters(); 

     Display display = ((WindowManager) mContext.getSystemService(android.content.Context.WINDOW_SERVICE)).getDefaultDisplay(); 

     if (display.getRotation() == Surface.ROTATION_0) { 

      System.out.println("Preview Width : " + width); 
      System.out.println("Preview Height : " + height); 

      parameters.setPreviewSize(width, height); 
      mCamera.setDisplayOrientation(90); 
     } 
    } 


    @Override 
    public void surfaceDestroyed(SurfaceHolder holder) { 
     mCamera.stopPreview(); 
     mCamera.release(); 
     mCamera = null; 
    } 

} 

請提供一些更多的細節,我會盡力,如果需要進一步調查。

我上的Xperia索拉運行與4.0.4。如果您可以爲我提供設備的內部版本號,這也會有所幫助。

+0

關於這個的任何消息? – Perty

+0

我已經提出了與內部工作人員,並等待迴應。 –

+0

我已經與一位應該能夠協助和/或評論這一整天的人聯繫。我將返回結果。 –

0

在這裏,我們遇到同樣的問題,我用你上面的代碼,看看它是如何工作的,以及它看起來像旋轉中心位移,從而旋轉90度時的畫像它只是顯示視圖的約10-20% 。

現在看來似乎是:

mCamera.setDisplayOrientation(90); 

這會導致問題。

這是可再現上:

  • 索尼XPERIA ST25i,採用Android 4.0.4版本(版本:6.1.1.B.1.54)
  • 索尼XPERIA獨奏MT27i,採用Android 4.0.4(建設:6.1.1.B.1.54)

這裏是相機參數,如果它們包含的任何信息:

01-22 16:04:01.015: D/CameraTest(1336): Haz camera: true 
01-22 16:04:01.095: D/TextLayoutCache(1336): Using debug level: 0 - Debug Enabled: 0 
01-22 16:04:01.425: D/libEGL(1336): loaded /system/lib/egl/libGLES_android.so 
01-22 16:04:01.505: D/libEGL(1336): loaded /system/lib/egl/libEGL_mali.so 
01-22 16:04:01.535: D/libEGL(1336): loaded /system/lib/egl/libGLESv1_CM_mali.so 
01-22 16:04:01.545: D/libEGL(1336): loaded /system/lib/egl/libGLESv2_mali.so 
01-22 16:04:01.725: D/OpenGLRenderer(1336): Enabling debug mode 0 
01-22 16:04:02.987: D/CameraTest(1336): preferred-preview-size-for-video=864x480 
01-22 16:04:02.987: D/CameraTest(1336): zoom=0 
01-22 16:04:02.987: D/CameraTest(1336): recording-hint=false 
01-22 16:04:02.987: D/CameraTest(1336): max-num-detected-faces-hw=5 
01-22 16:04:02.987: D/CameraTest(1336): zoom-supported=true 
01-22 16:04:02.987: D/CameraTest(1336): whitebalance=auto 
01-22 16:04:02.987: D/CameraTest(1336): scene-mode=auto 
01-22 16:04:02.987: D/CameraTest(1336): jpeg-quality=85 
01-22 16:04:02.987: D/CameraTest(1336): preview-format-values=yuv420sp,yuv420p 
01-22 16:04:02.987: D/CameraTest(1336): jpeg-thumbnail-quality=100 
01-22 16:04:02.987: D/CameraTest(1336): preview-format=yuv420sp 
01-22 16:04:02.987: D/CameraTest(1336): video-size-values=1280x720,864x480,720x480,640x480,352x288,320x240,176x144 
01-22 16:04:02.987: D/CameraTest(1336): preview-size=640x480 
01-22 16:04:02.987: D/CameraTest(1336): focal-length=3.5 
01-22 16:04:02.987: D/CameraTest(1336): flash-mode-values=off,auto,on,red-eye,torch 
01-22 16:04:02.987: D/CameraTest(1336): preview-frame-rate-values=15,30 
01-22 16:04:02.987: D/CameraTest(1336): max-num-metering-areas=0 
01-22 16:04:02.987: D/CameraTest(1336): preview-frame-rate=30 
01-22 16:04:02.987: D/CameraTest(1336): focus-mode-values=auto,infinity,macro,fixed,continuous-picture,continuous-video 
01-22 16:04:02.987: D/CameraTest(1336): jpeg-thumbnail-width=160 
01-22 16:04:02.987: D/CameraTest(1336): video-size=1280x720 
01-22 16:04:02.987: D/CameraTest(1336): scene-mode-values=auto,portrait,landscape,night,night-portrait,beach,snow,sports,party,barcode 
01-22 16:04:02.987: D/CameraTest(1336): preview-fps-range-values=(1000,15000),(1000,30000) 
01-22 16:04:02.987: D/CameraTest(1336): jpeg-thumbnail-size-values=160x120,0x0 
01-22 16:04:02.987: D/CameraTest(1336): zoom-ratios=100,107,115,123,132,141,152,162,174,187,200,214,230,246,264,283,303,325,348,373,400,429,459,492,528,566,606,650,696,746,800 
01-22 16:04:02.987: D/CameraTest(1336): preview-size-values=864x480,720x480,640x480,480x320,352x288,320x240,176x144 
01-22 16:04:02.987: D/CameraTest(1336): picture-size-values=2592x1944,2560x1440,1632x1224,1920x1080,640x480,480x320,320x240 
01-22 16:04:02.987: D/CameraTest(1336): preview-fps-range=1000,30000 
01-22 16:04:02.987: D/CameraTest(1336): auto-whitebalance-lock=false 
01-22 16:04:02.987: D/CameraTest(1336): min-exposure-compensation=-6 
01-22 16:04:02.987: D/CameraTest(1336): antibanding=auto 
01-22 16:04:02.987: D/CameraTest(1336): max-num-focus-areas=1 
01-22 16:04:02.987: D/CameraTest(1336): vertical-view-angle=360 
01-22 16:04:02.987: D/CameraTest(1336): horizontal-view-angle=360 
01-22 16:04:02.987: D/CameraTest(1336): video-stabilization-supported=false 
01-22 16:04:02.987: D/CameraTest(1336): jpeg-thumbnail-height=120 
01-22 16:04:02.987: D/CameraTest(1336): smooth-zoom-supported=true 
01-22 16:04:02.987: D/CameraTest(1336): focus-mode=macro 
01-22 16:04:02.987: D/CameraTest(1336): auto-whitebalance-lock-supported=true 
01-22 16:04:02.987: D/CameraTest(1336): video-frame-format=yuv420mb 
01-22 16:04:02.987: D/CameraTest(1336): max-num-detected-faces-sw=5 
01-22 16:04:02.987: D/CameraTest(1336): picture-format-values=jpeg 
01-22 16:04:02.987: D/CameraTest(1336): max-exposure-compensation=6 
01-22 16:04:02.987: D/CameraTest(1336): focus-areas=(0,0,0,0,0) 
01-22 16:04:02.987: D/CameraTest(1336): video-snapshot-supported=false 
01-22 16:04:02.987: D/CameraTest(1336): exposure-compensation=0 
01-22 16:04:02.987: D/CameraTest(1336): exposure-compensation-step=0.333333 
01-22 16:04:02.987: D/CameraTest(1336): flash-mode=off 
01-22 16:04:02.987: D/CameraTest(1336): auto-exposure-lock=false 
01-22 16:04:02.987: D/CameraTest(1336): effect-values=none,mono,negative,solarize,sepia,posterize 
01-22 16:04:02.987: D/CameraTest(1336): picture-size=2592x1944 
01-22 16:04:02.987: D/CameraTest(1336): max-zoom=30 
01-22 16:04:02.987: D/CameraTest(1336): effect=none 
01-22 16:04:02.987: D/CameraTest(1336): whitebalance-values=auto,incandescent,fluorescent,daylight,cloudy-daylight 
01-22 16:04:02.987: D/CameraTest(1336): picture-format=jpeg 
01-22 16:04:02.987: D/CameraTest(1336): focus-distances=Infinity,Infinity,Infinity 
01-22 16:04:02.987: D/CameraTest(1336): auto-exposure-lock-supported=true 
01-22 16:04:02.987: D/CameraTest(1336): antibanding-values=auto,50hz,60hz,off 
01-22 16:04:03.037: D/CameraTest(1336): Rotation : 0 
01-22 16:04:03.037: D/CameraTest(1336): Preview Width : 480 
01-22 16:04:03.037: D/CameraTest(1336): Preview Height : 744 
01-22 16:04:03.057: D/CameraTest(1336): Supported FPS : [[1000, 15000], [1000, 30000]] 
+1

剛剛嘗試過Xperia Function Tester,它有同樣的問題: https://play.google.com/store/apps/details?id=com.sonymobile.androidapp.functiontester 當使用power +音量進行屏幕截圖時它看起來不錯。 – Perty

0

我已經證實該問題與相機軟件有關。

不幸的是沒有可用的解決方法。

唯一的解決方案將是未來的固件更新,其中包括解決相機問題。

0

我有同樣的問題,在我的情況與索尼Experia還LT22I,當我與旋轉

mCamera.setDisplayOrientation屏幕(90);

只顯示約10-20%的視圖。最後我找到了這款手機的解決方案(補丁)。只有絲毫改變距頂部(我不知道爲什麼)認爲這個效果很好,是這樣的:

String model = (Build.MANUFACTURER+Build.MODEL).toUpperCase(Locale.getDefault()); 
if (model.equals(Constants.MODEL_EXCEPTION)) { 
    final ViewGroup.MarginLayoutParams lpt =(MarginLayoutParams)  
    surfaceView.getLayoutParams(); 
    lpt.setMargins(0,-150,0,0); 
    surfaceView.setLayoutParams(lpt); 
}