How can i capture a picture from front camera without preview and save it to SD card. Kindly help me with source code.
Create a Preview Class - Create a camera preview class that extends SurfaceView and implements the SurfaceHolder interface. This class previews the live images from the camera.
This is done as follows: Intent camera_intent = new Intent(MediaStore. ACTION_IMAGE_CAPTURE); startActivityForResult(camera_intent, pic_id); Now use the onActivityResult() method to get the result, here is the captured image.
 public void takePictureNoPreview(Context context){
          // open back facing camera by default
          Camera myCamera=Camera.open();
          if(myCamera!=null){
            try{
              //set camera parameters if you want to
              //...
              // here, the unused surface view and holder
              SurfaceView dummy=new SurfaceView(context)
              myCamera.setPreviewDisplay(dummy.getHolder());    
              myCamera.startPreview(); 
              myCamera.takePicture(null, null, getJpegCallback()):
            }finally{
              myCamera.close();
            }      
          }else{
            //booo, failed!
          }
          private PictureCallback getJpegCallback(){
            PictureCallback jpeg=new PictureCallback() {   
              @Override
              public void onPictureTaken(byte[] data, Camera camera) {
                FileOutputStream fos;
                try {
                  fos = new FileOutputStream("test.jpeg");
                  fos.write(data);
                  fos.close();
                }  catch (IOException e) {
                  //do something about it
                }
              }
            };
          }
        }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With