Most of the solutions on the Web are as follows:
Intent Intent = new Intent ("Android.media.action.IMAGE_CAPTURE");
Startactivityforresult (Intent,request_code_capture_cameia);
After the photo is completed, the callback:
protected void Onactivityresult (int requestcode, int resultcode, Intent data) {
if (resultcode! = RESULT_OK) {//RESULT_OK here is a constant that the system has customized
Return
}
if (data!=null) {
if (Requestcode = = Request_code_capture_cameia) {
Uri uri = Data.getdata ();
if (URI = = null) {
Use bundle to get data
Bundle Databundle = Data.getextras ();
if (databundle! = null) {
Bitmap photo = (Bitmap) databundle.get ("Data");
if (photo!=null) {
On some phones to get the photos, found that the size is very small
}
}
} else {
To display a picture by URI
Imageview.setimage (URI);
}
}
}
}
After the experiment, it was found that on some mobile phones, the images were obtained by URI, and all of them were taken to the actual size of the photograph.
There are also some phones that get captured photos through Data.getextras (). Get ("data"), but find that the actual size of the photos is small.
Through the study found the solution is as follows:
To override the calling method:
String filename = tools.getcurdatestr () + ". jpg";
Camerafile = new File (environment.getexternalstoragedirectory () + "/" +const.folder_voc_temp+ "/" +filename ");
Intent Intent = new Intent (mediastore.action_image_capture);
Intent.putextra (Mediastore.extra_output, Uri.fromfile (camerafile));
Startactivityforresult (Intent, Request_code_capture_cameia);
Callback Time:
protected void Onactivityresult (int requestcode, int resultcode, Intent data) {
if (camerafile.exists ()) {
Bitmap Bitmap = null;
try {
FileInputStream fis = new FileInputStream (camerafile);
Bitmap = Bitmapfactory.decodestream (FIS);
Fis.close ();
} catch (Exception e) {
E.printstacktrace ();
}
if (bitmap!=null) {
LOG.E (GetClass (). GetName (), (Bitmap.getwidth () + "," +bitmap.getheight ()));
}
}
}
This solves the problem.
Android Development Tutorial--the solution to the small size of photos taken by the system camera