[Phonegap+sencha Touch] Mobile development 30, PHONEGAP camera plug-in several issues

Source: Internet
Author: User

<span style= "FONT-SIZE:14PX;" >navigator.camera.getpicture (function (URI) {    //Get shot Picture path}, function (Err) {}, {    quality:70,    Allowedit:true,//finish the cropping edit    targetwidth:250,    targetheight:250,    destinationtype: navigator.camera.destinationtype.file_uri,//return URI    sourcetype:navigator.camera.picturesourcetype.camera,// Photo    savetophotoalbum:true});</span>

PhoneGap Camera plugin, there are several problems on Android system

1, do not get the true path of the photos taken , specific view blog "Mobile Development 29 Android Navigator.camera.getPicture get pictures of the true path"

2, Targetwidth or targetheight more than 512 pixels , the photo and crop, theapp will crash , or the app does not respond (online Some people say there are 256 pixels, my Meizu MX3 test is 512 pixels)

3, only in targetwidth = = Targetheight time, cut the picture will limit the proportion of 1:1; otherwise, you cannot limit the length and width of the cropping graph , you can adjust any. And we sometimes have to limit the length-to-width ratio of the cropped image.

4, if the Targetwidth and Targetheight are set to 250*250, and the actual clipping resolution is only 100*100, the cropped picture will have black edge .


Workaround:

1, the first problem, the solution to see the blog "Mobile Development 29 Android Navigator.camera.getPicture get pictures of the true path"

2. The second, third and fourth issues are improved as follows:

into the plugin directory, locate this file, Org.apache.cordova.camera\src\android\cameralauncher.java
near line 307 (GetImage method ):
if (targetheight > 0 && targetwidth > 0) {//Limit reduction ratio  Intent.putextra ("Aspectx", targetwidth);  Intent.putextra ("Aspecty", Targetheight);}

near Line 361 (Performcrop method ):
if (targetheight > 0 && targetwidth > 0) {//Limit reduction ratio    Cropintent.putextra ("Aspectx", targetwidth);    Cropintent.putextra ("Aspecty", Targetheight);} Retrieve data on return//Cropintent.putextra ("Return-data", true); Cropintent.putextra ("Return-data", false); Save as a file without returning bitmap data, resolving the phenomenon of large image collapse Cropintent.putextra ("scale", true); Remove Black Edge Cropintent.putextra ("scaleupifneeded", true); Remove black edge file photo = Createcapturefile (encodingtype); Croppeduri = Uri.fromfile (photo); Cropintent.putextra ( Android.provider.MediaStore.EXTRA_OUTPUT, Croppeduri); Save Crop Chart as temp file

674 line near ( onactivityresult method ):
/* Comment out the following code * Bundle extras = Intent.getextras (); Get the cropped bitmap * Bitmap thepic = extras.getparcelable ("Data");     if (thepic = = * Null) {this.failpicture ("Crop returned no Data"); return;}     * *//Now Save the bitmap to a file outputstream fOut = null; * File Temp_file = new file (Gettempdirectorypath (), * System.currenttimemillis () + ". jpg");     try {* Temp_file.createnewfile (); fOut = new * FileOutputStream (temp_file); * Thepic.compress (Bitmap.CompressFormat.JPEG, this.mquality, * fOut); Fout.flush (); Fout.close ();     } catch * (FileNotFoundException e) {e.printstacktrace ();} catch * (IOException e) {e.printstacktrace ();}     */File photo = Createcapturefile (Encodingtype);    File Temp_file = new file (Gettempdirectorypath (), System.currenttimemillis () + ". jpg"); if (photo.exists ()) Photo.renameto (temp_file); Get cropped image temp File////Send Uri back to JavaScript for viewing image this.callbackcontext. suCcess (Uri.fromfile (temp_file). toString ()); 

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.