Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
New Developer
Posts: 65
Registered: ‎08-07-2013
My Device: Blackberry Torch 9800
My Carrier: Mobile App Development

How to pick the image and convert base64 for Blackberry 10 Webworks?

Hi All,

 

I have developed web application for Blackberry Z10 using Ripple Emulator and Blackberry Webworks SDK 1.0.4.11. In that i have to upload the image to web server. Here i have the problem to pick the image from gallery then need to show the selected images after need to convert base64.Please help me to do this. Thanks in Advance

 

With Regards,

Marimuthu_P

Developer
Posts: 123
Registered: ‎07-11-2011
My Device: 8900
My Carrier: Airtel

Re: How to pick the image and convert base64 for Blackberry 10 Webworks?

Below is the code for converting to Base 64:

var img = document.createElement('Image');
var canvas = document.createElement('Canvas');
 
function getBase64Image(p){
    img.onload=function(){
       canvas.width = img.width;
       canvas.height = img.height;
       var ctx = canvas.getContext("2d");
       ctx.drawImage(img, 0, 0);
       var imgStr = canvas.toDataURL("image/jpg");
       alert("image loaded----\n"+imgStr);
    };
   img.setAttribute("src", p);
}

Also, please refer to below link if this helps you:

http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/Getting-incorrect-Base64-string-...