1. Call the System camera
// Photography public void takephotos (view) {intent cameraintent = new intent (Android. provider. mediastore. action_image_capture); startactivityforresult (cameraintent, camera_request );}
@ Overrideprotected void onactivityresult (INT requestcode, int resultcode, intent data) {// process it here // todo auto-generated method stubif (requestcode = camera_request & resultcode = result_ OK & data. getextras (). get ("data ")! = NULL) {If (RSD. getphoto1url ()! = NULL) {// Delete the information of the previous image deleteimgage (RSD. getphoto1url ();} bitmap photo = (Bitmap) data. getextras (). get ("data"); file basefile = filehelper. getpicbasefile (); If (basefile = NULL) {showlongmessage ("SD card unavailable, please check the SD card situation"); return;} string filename = getfilename (); // The RSD of the image name. setphoto1url (filename); savebitmap (photo, filename, basefile); imgphoto. setimagebitmap (photo);} super. onactivityresult (requestcode, resultcode, data );}
2.
// Get the file name private string getfilename () {simpledateformat SDF = new simpledateformat ("yyyymmddhhmmss", locale. getdefault (); Date crudate = calendar. getinstance (). gettime (); string strdate = SDF. format (crudate); string username = config. getuser (question_record.this ). getloginname (); string filename = username + strdate + ". jpg "; return filename ;}
3.
// Save the image private void savebitmap (Bitmap bitmap, string filename, file basefile) {fileoutputstream Bos = NULL; file imgfile = new file (basefile, "/" + filename ); try {Bos = new fileoutputstream (imgfile); bitmap. compress (bitmap. compressformat. JPEG, 100, Bos);} catch (filenotfoundexception e) {// todo auto-generated catch blocke. printstacktrace ();} finally {try {Bos. flush (); Bos. close ();} catch (ioexception e) {// todo auto-generated catch blocke. printstacktrace ();}}}
4. File help class
Public class filehelper {Private Static string filepath = "inspect/image";/*** Image Base path * @ return */public static file getpicbasefile () {If (environment. getexternalstoragestate (). equals (environment. media_mounted) {// file available file F = new file (environment. getexternalstoragedirectory (), filepath); If (! F. exists () F. mkdirs (); Return F ;}else {return NULL ;}}}
5. The above code has been very detailed. If you have any questions about shoes you cannot understand, contact me.