相机预览视图,水平时应垂直在HTC Tattoo上工作正常,打破了Nexus

时间:2010-06-09 22:41:14

标签: java android camera

我使用的是Nexus One,相机应垂直显示,反之亦然。我不知道出了什么问题。该代码在HTC纹身上工作正常。任何人都知道什么是错的?

 class Preview extends SurfaceView implements SurfaceHolder.Callback {
SurfaceHolder mHolder;
Camera mCamera;

Preview(Context context) {
    super(context);

    // Install a SurfaceHolder.Callback so we get notified when
    //the
    // underlying surface is created and destroyed.
    mHolder = getHolder();
    mHolder.addCallback(this);
    mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}

public void surfaceCreated(SurfaceHolder holder) {
    // The Surface has been created, acquire the camera and tell
    //it where
    // to draw.
    mCamera = Camera.open();
    try {
        mCamera.setPreviewDisplay(holder);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

public void surfaceDestroyed(SurfaceHolder holder) {
    // Surface will be destroyed when we return, so stop the
    //preview.
    // Because the CameraDevice object is not a shared resource,
    //it's very
    // important to release it when the activity is paused.
    mCamera.stopPreview();
    mCamera = null;
}

public void surfaceChanged(SurfaceHolder holder, int format, int
w, int h) {
    // Now that the size is known, set up the camera parameters
    //and begin
    // the preview.
    Camera.Parameters parameters = mCamera.getParameters();
    parameters.setPreviewSize(800, 480);
    mCamera.setParameters(parameters);
    mCamera.startPreview();
}

1 个答案:

答案 0 :(得分:1)

搞定了。我加了..

parameters.set("orientation", "portrait");

CommonsWare给了我一个想法就是这个问题感谢男人:)