Phonegap Study Notes (4) Local images and cameras

Source: Internet
Author: User

Phonegap: The image object is camera. This object has only one method, getpicture (). The method parameters are as follows:

Quality: an integer between 0 and. Set the image quality. If the local image is loaded as an address, this parameter is invalid.

Destinationtype: Camera. destinationtype. file_url | camera. destinationtype. data_url

If it is file_url, the image is returned in the form of a local address. If it is data_url, the image is returned in the form of base64. the src attribute of IMG needs to be spliced with the base64 prefix "data: image/JPEG; base64 ,"

For example, image. src = "data: image/JPEG; base64," + imagedata;

Sourcetype: Camera. picturesourcetype. savedphotoalbum | camera. picturesourcetype. photolibrary | camera. picturesourcetype. Camera

There is no difference between savedphotoalbum and photolibrary on Android devices. They both show the same photo gallery. Camera indicates that images are taken using cameras.

Example:

1 Document. addeventlistener ("deviceready", function () {2 try {3 Init (); 4} catch (e) {alert (e) ;}5}, false ); 6 7 function Init () {8 // var Options = {quality: 40, destinationtype: Camera. destinationtype. file_url, sourcetype: Camera. picturesourcetype. savedphotoalbum}; // select 9 var Options = {quality: 40, destinationtype: camera from the album. destinationtype. file_url, sourcetype: Camera. picturesourcetype. camera, allowedit: true}; // use camera 10 navigator. camera. getpicture (onsuccess, onerror, options); 11} 12 function onsuccess (imgurl) {13 MSG. innerhtml = imgurl; 14 IMG. src = imgurl; 15} 16 function onerror (Message) {17 MSG. innerhtml = message; 18}

 

Phonegap Study Notes (4) Local images and cameras

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.