-1

我正在尝试从这篇文章中学习增强现实基础知识:http: //www.devx.com/wireless/Article/42482/0/page/2

当它运行时,相机采用相反的方向。我的问题是如何使用相机获得固定和正常的视图。这是 CustomCameraView 类:

package com.syariati.camera;

import android.content.Context;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class CustomCameraView extends SurfaceView {
    Camera camera;
    SurfaceHolder surfaceHolder;

    public CustomCameraView(Context context){
        super(context);
        surfaceHolder = this.getHolder();
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        surfaceHolder.addCallback(surfaceHolderListener);
    }

    SurfaceHolder.Callback surfaceHolderListener = new SurfaceHolder.Callback() {

        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {
            // TODO Auto-generated method stub
            camera.stopPreview();
            camera.release();
        }

        @Override
        public void surfaceCreated(SurfaceHolder holder) {
            // TODO Auto-generated method stub
            camera = Camera.open();
            try{
                camera.setPreviewDisplay(surfaceHolder);
            }
            catch(Exception e){
                e.printStackTrace();
            }
        }

        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width,
                int height) {
            // TODO Auto-generated method stub
            Parameters params = camera.getParameters();
            params.setPictureFormat(PixelFormat.JPEG);
            camera.setParameters(params);
            camera.startPreview();
        }
    };
}

我应该在参数上添加另一种方法吗?

对不起,我的英语不好。谢谢你。

问题就是这样解决的。

添加 :

camera.setDisplayOrientation(90);

Android - 相机预览是横向的

4

2 回答 2

2

根据您的要求设置方向度,因为我有用户 90 用于前置摄像头和 270 度用于后置摄像头:

Camera.Parameters params = camera.getParameters();
params.set("rotation", 90);
camera.setParameters(params);
于 2012-12-22T06:57:54.167 回答
0

转到您的应用程序 AndroidManifest.xml 文件,然后按照

Application tab -> select CustomCameraView activity -> 
attributes for CustomCameraView activity -> screen orientation -> select portrait.

然后运行它-Njoy...

于 2012-03-25T13:51:27.983 回答