Camera API android上的异常图片

时间:2012-03-06 01:55:03

标签: android api camera

  

可能重复:
  Android Camera in Portrait on SurfaceView

我不知道如何修复它。我需要某人的帮助,我是android新手。这是第一篇文章。我很抱歉我的英语很差,最好的问候

public class MainActivity extends Activity implements SurfaceHolder.Callback{

    private static final String TAG = "CAMERA_TUTORIAL";
    private SurfaceView surfaceView;
    private SurfaceHolder surfaceHolder;
    private Camera camera;
    private boolean previewRunning;

        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                surfaceView = (SurfaceView) findViewById(R.id.surface_camera);
                surfaceHolder = surfaceView.getHolder();
                surfaceHolder.addCallback(this);
                surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        }

        @Override
    public void surfaceCreated(SurfaceHolder holder) {
        camera = Camera.open();
        if (camera != null){
            Camera.Parameters params = camera.getParameters();
            camera.setParameters(params);
        }
        else {
            Toast.makeText(getApplicationContext(), "Camera not available!", Toast.LENGTH_LONG).show();
            finish();
        }
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
        if (previewRunning) {
            camera.stopPreview();
        }
        Camera.Parameters parameters = camera.getParameters();
        List<Camera.Size> focusModes = parameters.getSupportedPreviewSizes();

        if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO))
            {
                parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
            }

       try {
            camera.setPreviewDisplay(holder);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        camera.setParameters(parameters);
        camera.startPreview();


    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        camera.stopPreview();
        previewRunning = false;
        camera.release();
    }
}

这是我的形象。我已经在HTC启发了它

1

0 个答案:

没有答案