How to take pictures from the camera without preview when my app starts?

前端 未结 5 706
南方客
南方客 2020-12-01 02:00

Now all I want is an app that just takes the picture from the camera upon launching. No layout, no camera preview...nothing, just a simple app icon to launch the app. Once l

5条回答
  •  悲&欢浪女
    2020-12-01 02:20

    As of API-Level 11 the SurfaceTexture was added. With it a SurfaceView is no longer needed. I tested the following code with my Samsung Galaxy S3 Neo.

    mCamera = Camera.open();
    try {
        mCamera.setPreviewTexture(new SurfaceTexture(10));
    } catch (IOException e1) {
        Log.e(Version.APP_ID, e1.getMessage());
    }
    
    Parameters params = mCamera.getParameters();
    params.setPreviewSize(640, 480);
    params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
    params.setPictureFormat(ImageFormat.JPEG);
    mCamera.setParameters(params);
    mCamera.startPreview();
    mCamera.takePicture(null, null, null, new PictureCallback() {
        @Override
        public void onPictureTaken(byte[] data, Camera camera) {
            Log.i(Version.APP_ID, "picture-taken");
        }
    });
    

提交回复
热议问题