2013-07-25 5 views
6

मुझे एक एप्लिकेशन डिज़ाइन करना है, उस एप्लिकेशन को लेआउट में बिना किसी उपयोगकर्ता इंटरफ़ेस (जैसे बटन के क्लिक ...) के बिना कैमरे से तस्वीर लेनी है और तस्वीर को स्टोर करना है?उपयोगकर्ता इंटरफ़ेस के बिना एंड्रॉइड एप्लिकेशन में चित्र कैसे लें ..?

उत्तर

3
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()); 
       } 

    } 
}; 
+1

धन्यवाद, बहुत मदद की ... – user2545522

+0

कॉल 'mCamera.startPreview()' 'safeCameraOpen' के बाद, startPreview बुला बिना यह काम नहीं करेगा – Vlad

संबंधित मुद्दे