[ 
https://issues.apache.org/jira/browse/CB-1045?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13436004#comment-13436004
 ] 

Braden Shepherdson commented on CB-1045:
----------------------------------------

Base64 image data may be obtained from the returned URL in Javascript. If you 
create an image, set its src to the URL, and then in onload create a canvas, 
size it, draw the image to it, and extract the base64 with toDataURL. See code:

{code:javascript}
navigator.contacts.find(['displayName', 'photos'],
  function(contacts) {
    console.log('Found ' + contacts.length + ' contacts.');
    for (var i = 0; i < contacts.length; i++) {
      if (contacts[i].photos) {
        for (var j = 0; j < contacts[i].photos.length; j++) {
          var img = new Image();
          img.onload = function() {
            var canvas = document.createElement("canvas");
            canvas.width = img.width;
            canvas.height = img.height;
            var ctx = canvas.getContext("2d");
            ctx.drawImage(img, 0, 0);
            try {
              var data = canvas.toDataURL("image/png");
              // data == "data:image/png;base64,BASE64_DATA_HERE..."
            } catch(e) {
              console.log('toDataUrl failed: ' + e);
            }
          };

          try {
            console.log('trying to set img.src to ' + 
contacts[i].photos[j].value);
            img.src = contacts[i].photos[j].value;
            console.log('img.src = ' + img.src);
          } catch (e) {
            console.log('failed to load image: ' + e);
          }
        }
      }
    }
  }, function(err) {
    alert(err);
  });
{code}
                
> Obtaining image pointer from contact photo URI
> ----------------------------------------------
>
>                 Key: CB-1045
>                 URL: https://issues.apache.org/jira/browse/CB-1045
>             Project: Apache Cordova
>          Issue Type: Wish
>          Components: Android
>    Affects Versions: 1.9.0
>            Reporter: Paul Davis
>            Assignee: Simon MacDonald
>
> This issue was discussed with Simon Mac Donald on the Google PhoneGap Groups. 
>  I have been attempting to obtain an image from a contacts URI but I believe 
> this is not currently handled in the PhoneGap Api.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to