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 Contributor
Posts: 5
Registered: ‎03-30-2011
My Device: Playbook, Torch
My Carrier: Rogers

Re: stringToblog save image problem

I just tested on my side and it works like a charm !

 

Thanks a lot for your quick help

Regular Contributor
Posts: 63
Registered: ‎06-08-2012
My Device: BlackBerry
My Carrier: BlackBerry

Re: stringToblog save image problem

Hi everyone,

 

I try to save image (follow the guide)

But it is nothing, no error. And I do not know reason.

 

My config.xml:

 

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:rim="http://www.blackberry.com/ns/widgets" id="idRetailStar" version="1.0.0.6">
<name>My App</name>
<description>App Discription</description>
<author email="abc@gmail.com">An Pham</author>

<feature id="blackberry.identity" required="true" version="1.0.0.0"/>
<feature id="blackberry.message" required="true" version="1.0.0.0"/>
<feature id="blackberry.io.dir" required="true" version="1.0.0.0"/>
<feature id="blackberry.io.file" required="true" version="1.0.0.0"/>
<feature id="blackberry.invoke.CameraArguments" required="true" version="1.0.0.0"/>
<feature id="blackberry.media.camera"/>
<feature id="blackberry.find" required="true" version="1.0.0.0"/>
<feature id="blackberry.app" required="true" version="1.0.0.0"/>


<feature id="blackberry.system" />
<feature id="blackberry.connection" />
<feature id="blackberry.invoke"/>
<feature id="blackberry.utils" />

<feature id="blackberry.app.event"/>

 

<icon rim:hover="false" src="WebContent/images/app_logo.png"/>
<icon rim:hover="true" src="WebContent/images/app_logo.png"/>

<content src="login.html">

</content>

<rim:smileysurprised:rientation mode="landscape" />


<rim:loadingScreen backgroundColor="#063a6b"
onFirstLaunch="true"
onRemotePageLaunch="true"
onLocalPageLoad = "true">
<rim:transitionEffect type="zoomIn" direction="slideOver" duration="1000"/>
</rim:loadingScreen>

<access subdomains="true" uri="file:///accounts/"/>

<rim:smileytongue:ermissions>
<rim:smileytongue:ermit>access_shared</rim:smileytongue:ermit>
<rim:smileytongue:ermit>read_geolocation</rim:smileytongue:ermit>
<rim:smileytongue:ermit>use_camera</rim:smileytongue:ermit>
</rim:smileytongue:ermissions>

</widget>

 

And my code:

 

try {
var _now = new Date();
var fileName = _now.getDate().toString()+(_now.getMonth()+1).toString()+_now.getFullYear().toString()+_now.getHours().toString()+_now.getMinutes().toString()+_now.getSeconds();
var dirs = blackberry.io.dir.appDirs;
var image_path = dirs.shared.camera.path+'/Rs'+fileName+'.jpg';
/*fileDir = blackberry.io.dir.appDirs.app.storage.path + "/dir1";
blackberry.io.dir.createNewDir(fileDir);*/

alert(image_path);

var image01 = document.createElement('img');
var myCanvas = document.createElement("canvas");
var mycanvas_context;

image01.onload = function() {
myCanvas.width = image01.width;
myCanvas.height = image01.height;
mycanvas_context = myCanvas.getContext("2d");
alert(image01.width + ' x '+image01.height);

mycanvas_context.drawImage(image01,0,0);

final_image = myCanvas.toDataURL("image/jpeg");
//final_image = final_image.replace('data:image/png;base64,', '');

alert('Data URL: '+final_image);

final_image_blob = blackberry.utils.stringToBlob(final_image,"binary");
try {
blackberry.io.file.saveFile(image_path, final_image_blob);
} catch (err) {
alert('saveFile Err. '+err);
}
};
image01.src='http://cdn.sheknows.com/articles/2012/02/Sarah_Parenting/baby-names-baby-in-towel2.jpg';


} catch(e) {
alert("Err. "+e);
}

 

See your response soon!

 

Regards,

An Pham

Regular Contributor
Posts: 63
Registered: ‎06-08-2012
My Device: BlackBerry
My Carrier: BlackBerry

Re: stringToblog save image problem

And I change: final_image_blob = blackberry.utils.stringToBlob(final_image,"BASE64");
And it is nothing????
BlackBerry Development Advisor
Posts: 835
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: stringToblog save image problem

You are mixing jpeg and png in there.

 

get the data URL as PNG and then strip off the dataURL stuff. Then convert it to a Binary blob. You MUST have the path installed in your WebWorks SDK to use the 'binary' content type as below:

 

var myimagedata = canvas.toDataURL();

myimagedata = myimagedata.replace('data:image/png;base64,', '');

var blobdata = blackberry.utils.stringToBlob(myimagedata, 'binary');

 Pull request with patch is here: https://github.com/blackberry/WebWorks-TabletOS/pull/57/files

Tim Windsor
Open Source Technical Lead
Contributor
Posts: 19
Registered: ‎12-26-2010
My Device: 9800

Re: stringToblog save image problem

Hello Twindsor,

 

This is a question related to what we are discussing. I am trying to send multiple images to the backend webservice written in .net. however i am only able to send one PNG image by using these lines

 

var dataURL = canvas.toDataURL("image/png");

return dataURL.replace(/^data:image\/(png|jpeg);base64,/, "");

 

However if i try sending JPEGs i can send mutliple images, but all the images received on server side are distorted. This behavior is noticed when using the JPEG format. Could you help.

 

var dataURL = canvas.toDataURL("image/jpeg"); 

return dataURL.replace(/^data:image\/(png|jpeg);base64,/, "");


My requirement is to send mutliple base64 images to the server. Please also mentioned if there any limit applies. I am sending it on OS 7 (9900, 9810). 

New Contributor
Posts: 8
Registered: ‎07-25-2012
My Device: 9300
My Carrier: iusacell

Re: stringToblog save image problem

Hi, 

 

Reading th article i notice that the patch is only for the stringToBlob of the playbook, is there something similar for the SDK 2.3.1 for smartphones?

 

Thanks.

Contributor
Posts: 19
Registered: ‎12-26-2010
My Device: 9800

Re: stringToblog save image problem

you can try editing the file below and share your results

 

C:\Program Files (x86)\Research In Motion\BlackBerry WebWorks SDK 2.3.0.9\ext\blackberry.utils\blackberry\utils\StringToBlobFunction.java

New Contributor
Posts: 8
Registered: ‎07-25-2012
My Device: 9300
My Carrier: iusacell

Re: stringToblog save image problem

Thanks i will try that, and another question, why is necesary to convert the response to a binary file to save it as an image?

 

Contributor
Posts: 19
Registered: ‎12-26-2010
My Device: 9800

Re: stringToblog save image problem

I believe saving it directly using the base64 encoding may give issues @ times. Binary is preferable. However, i am not an expert in this area and would like some one else to comment over it.

New Contributor
Posts: 8
Registered: ‎07-25-2012
My Device: 9300
My Carrier: iusacell

Re: stringToblog save image problem

Using stringToBlob (responseText,"BASE64") in fact saves me the file...the problem is the i can`t open the file like an image, and i can`t figure it out how to save the image in binary