LG Optimus Black上的相机预览

时间:2012-02-05 16:59:43

标签: android

我有一个LG Optimus Black(Android 2.2.2)的客户,每次黑色都有相机预览。在其他设备上一切正常。这款手机有问题或有人有解决方案吗?我的相机预览代码如下。

    SurfaceHolder.Callback mySurfaceHolderCallback = new SurfaceHolder.Callback()
{
    @Override
    public void surfaceCreated(SurfaceHolder holder)
    {
        Log.i("GMG", "surfaceCreated");

        try
        {
            mCamera = Camera.open();
            holder.setFormat(PixelFormat.TRANSLUCENT);
            mCamera.setPreviewDisplay(holder);
        }
        catch (IOException e)
        {
            if (mCamera == null) return;
            mPreviewRunning= false;
            mCamera.release();
            mCamera = null;             
        }
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder)
    {
        Log.i("GMG", "surfaceDestroyed");
        if (mCamera != null)
        {
            mCamera.stopPreview();
            mPreviewRunning= false;
            mCamera.release();
            mCamera = null;
        }
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
    {
        Log.i("GMG", "surfaceChanged");

        if (mCamera != null)
        {
            if(mPreviewRunning) mCamera.stopPreview();

            Camera.Parameters p = mCamera.getParameters();

            //Angolo visivo della fotocamera
            angoloVisualeX = p.getHorizontalViewAngle();
            angoloVisualeY = p.getVerticalViewAngle();

            //Formati della preview
            supportedPreviewSize = p.getSupportedPreviewSizes();            
            int preview_width = supportedPreviewSize.get(supportedPreviewSize.size()-1).width;
            int preview_height = supportedPreviewSize.get(supportedPreviewSize.size()-1).height;
            p.setPreviewSize(preview_width, preview_height);

            //Set camera orientation
            Display display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
            if(display.getRotation() == Surface.ROTATION_0) mCamera.setDisplayOrientation(90);
            if(display.getRotation() == Surface.ROTATION_270) mCamera.setDisplayOrientation(180);

            mCamera.setParameters(p);
            mCamera.startPreview();
            mPreviewRunning = true;
        }
    }
};

最好的问候。

1 个答案:

答案 0 :(得分:1)

我已经解决了,我不知道为什么,但是有一个大的相机预览我没有问题

更改

        int preview_width = supportedPreviewSize.get(supportedPreviewSize.size()-1).width;
        int preview_height = supportedPreviewSize.get(supportedPreviewSize.size()-1).height;

        int preview_width = supportedPreviewSize.get(0).width;
        int preview_height = supportedPreviewSize.get(0).height;