Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to take pictures in android application without the user Interface..?

Tags:

android

camera

I have to design an application, that application has to take the picture from the camera without displaying it in the layout and without any user Interface (like click of a button....) and store the picture?

like image 241
user2545522 Avatar asked Jul 25 '13 13:07

user2545522


People also ask

How do I get my Android to automatically take pictures?

The menu option (look for the gear icon) can be found to the left of the Capture button. Tap on the gear icon to open several menu options. Find the Timer option from the menu. Tapping on the Timer option will bring up the auto-timer which can be set to 2, 5, 10, 15, or 30 seconds.


1 Answers

Camera mCamera; 
private boolean safeCameraOpen(int id) {
boolean qOpened = false;

    try {
        releaseCamera();
        mCamera = Camera.open(id);
        qOpened = (mCamera != null);
    } catch (Exception e) {
        Log.e(getString(R.string.app_name), "failed to open Camera");
        e.printStackTrace();
    }

    return qOpened;    
}

private void releaseCamera() {
    if (mCamera != null) {
        mCamera.release();
        mCamera = null;
    }
}

//somewhere in your code call this:
mCamera.takePicture(null, null, mCall);


Camera.PictureCallback mCall = new Camera.PictureCallback() {

   public void onPictureTaken(byte[] data, Camera camera) {
         //decode the data obtained by the camera into a Bitmap

         FileOutputStream outStream = null;
              try {
                  outStream = new FileOutputStream("/sdcard/Image.jpg");
                  outStream.write(data);
                  outStream.close();
              } catch (FileNotFoundException e){
                  Log.d("CAMERA", e.getMessage());
              } catch (IOException e){
                  Log.d("CAMERA", e.getMessage());
              }

   }
};
like image 53
Semyon Danilov Avatar answered Oct 31 '22 16:10

Semyon Danilov