我有一个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;
        }
    }
};


最好的祝福。

最佳答案

我已经解决了,我不知道为什么,但是用大尺寸的相机预览我没有问题
更改

        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;

10-07 19:34