Android Development Tutorial--the solution to the small size of photos taken by the system camera

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.