我正在尝试从这篇文章中学习增强现实基础知识: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);