2017年4月6日星期四

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

Camera mCamera = Camera.open();
try {
   mCamera.setPreviewTexture(new SurfaceTexture(10));
} catch (IOException e1) {
  }

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) {
           FileOutputStream outStream = null;
          try {
               outStream = new FileOutputStream( getFilesDir()+File.separator+"aaaa.jpg");
               outStream.write(data);
               outStream.close();

          } catch (FileNotFoundException e) {
               e.printStackTrace();
          } catch (IOException e) {
               e.printStackTrace();
          } finally{
              camera.stopPreview();
             camera.release();
             camera = null;
         }
     }
 });

没有评论:

发表评论