android startVideo拉伸并处于横向模式

时间:2012-10-12 15:02:42

标签: android video camera

我的代码中存在一些问题。我必须启动相机并捕获它,所以这是我的代码,我的问题是相机以一些奇怪的视图开始,如横向模式和拉伸。

 mVideoCaptureView = (SurfaceView) findViewById(R.id.cameraView);
        SurfaceHolder videoCaptureViewHolder = mVideoCaptureView.getHolder();
        videoCaptureViewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        videoCaptureViewHolder.addCallback(new Callback() {
            public void surfaceDestroyed(SurfaceHolder holder) {
            }

            public void surfaceCreated(SurfaceHolder holder) {
                startVideo();
            }

            public void surfaceChanged(SurfaceHolder holder, int format,
                    int width, int height) {
            }
        }); 

startVideo()函数

private void startVideo() {
        if(mCamera != null) return;
        SurfaceHolder videoCaptureViewHolder = null;
        try {
            mCamera = Camera.open();
        } catch (RuntimeException e) {
            Log.e("CameraTest", "Camera Open filed");
            return;
        }
        mCamera.setErrorCallback(new ErrorCallback() {
            public void onError(int error, Camera camera) {
            }
        }); 
        Camera.Parameters parameters = mCamera.getParameters();
        parameters.setPreviewFrameRate(30);

        mCamera.setParameters(parameters);
        if (null != mVideoCaptureView)
            videoCaptureViewHolder = mVideoCaptureView.getHolder();
        try {
            mCamera.setPreviewDisplay(videoCaptureViewHolder);
        } catch (Throwable t) {
        }

        try {
            mCamera.startPreview();
        } catch (Throwable e) {
            mCamera.release();
            mCamera = null;
            return;
        }
    }

另外,我必须在相机视图中添加自己的buttonsImageButtons 谢谢 问候 对不起英语

1 个答案:

答案 0 :(得分:0)

Camera`camera.setDisplayOrientation(90)有一些功能;我是从here

得到的