Method One:
This method will be sent directly to the application by the camera, but the compressed picture is returned, the display is not clear
/** start camera */private void Intentcamera () {try {Intent cameraintent = new Intent (Mediastore.action_image_ca Pture); Startactivityforresult (cameraintent, 0); } catch (Activitynotfoundexception e) {e.printstacktrace (); }}
/** gets the picture in Onactivityresult */private void Getimgfromcamera () {Bundle bundle = Data.getextras (); BM = (Bitmap) bundle.get ("Data"); if (BM! = null) bm.recycle (); BM = (Bitmap) Data.getextras (). Get ("data"); if (BM! = null) {IMG.SETIMAGEBITMAP (BM); }}
Method Two:
This method is what you get, but it generates temporary files on the SD card
/*** Open Camera */private void intentcamera () { Intent cameraintent = new intent (Android.provider.MediaStore.ACTION_IMAGE_CAPTURE); file file = new file (Environment.getexternalstoragedirectory () + "/images"); if (!file.exists ()) { File.mkdirs (); } uri muri = uri.fromfile ( new file (Environment.getexternalstoragedirectory () + "/images/", "Cameraimg" + string.valueof ( System.currenttimemillis ()) + ". jpg"); cameraintent.putextra ( Android.provider.mediastore.extra_output, muri); cameraintent.putextra (" Return-data ", true); sTartactivityforresult (cameraintent, 1);}
/*** gets the data returned by the camera */private void getimgfromcamera () { ContentResolver cr = This.getcontentresolver (); try { if (camerabitmap != null) Camerabitmap.recycle ();// if not released, keep taking pictures, will not have enough memory Camerabitmap = bitmapfactory.decodestream (Cr.openinputstream (MUri)); if (bm != null) { img.setimagebitmap (BM); } } catch (filenotfoundexception e) { // Todo auto-generated catch&nbSP;BLOCK        LOG.E ("error", "Get picture from camera failed ====="); e.printstacktrace (); }}
Two ways Android gets pictures from camera