2

我开发了一个基于相机的应用程序。它运行良好,但带有 Android 4.0 的 Camera 和 Sony Xperia Sola OS 存在一个问题。

问题如下:

当我从我的应用程序相机预览启动相机时,索尼 Xperia Sola 设备和任何其他设备 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);
    }

请帮我找到解决方案。

4

4 回答 4

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;
    }

}

请提供更多详细信息,如有必要,我将尝试进一步调查。

我在 4.0.4 的 Xperia Sola 上运行。如果您可以向我提供您设备的内部版本号,这也会有所帮助。

于 2012-11-29T16:29:23.493 回答
0

我遇到了同样的问题,在我使用 Sony 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);
}
于 2014-06-06T11:41:17.423 回答
0

我已确认该问题与相机软件有关。

不幸的是,没有可用的解决方法。

唯一的解决方案将是未来的固件更新,其中包括对相机问题的修复。

于 2013-03-07T09:59:42.690 回答
0

我们在这里遇到了同样的问题,我用你上面的代码来看看它是如何工作的,看起来旋转中心被移位了,所以当旋转 90 度到纵向时,它只显示了大约 10-20% 的视图。

它似乎是:

mCamera.setDisplayOrientation(90);

这导致了问题。

这可以在以下位置重现:

  • 索尼 Xperia ST25i,Android 版本 4.0.4(内部版本:6.1.1.B.1.54)
  • 索尼 Xperia Solo 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]]
于 2013-01-22T15:21:44.010 回答