02-23-2012 08:48 PM
Hi,
I am having a problem using stringToBlob and the playbook. I am able to save a file to the photos directory the problem is it is not a "png" file. the file size seems about right it is 300ish k in size. this is my function anybody have any ideas? i read this was suppose to work with the latest SDK. I also am running the newest OS update.
function SaveCanvas2PhotoRoll()
{
var canvas = document.getElementById("myCanvas");
// canvas.toDataURL().replace('data:image/png;base64
var myimagedata = canvas.toDataURL();
var blobdata = blackberry.utils.stringToBlob(myimagedata, "BASE64");
var numRand = Math.floor(Math.random()*9999999);
var thePathnName = "file:///accounts/1000/shared/photos/iCanColor" + numRand.toString() +".png";
console.log(thePathnName);
blackberry.io.file.saveFile(thePathnName, blobdata);
// myAlert("Your picture has been saved to the Photos roll", "Picture Saved", "Close");
}
thanks
tim
Solved! Go to Solution.
02-27-2012 07:31 PM
Anybody have anything on this? I have tried a million things with no luck, I am following what was discussed in other t
Sorry if i sound brash... it is so frustrating to be so close and you know this type of functionality should be there somewhere...
03-12-2012 04:24 PM
Hi. Same problem for me. Saved images are not valid. I'm still looking for a way to save canvas to image files...
03-12-2012 11:06 PM
It appears the blackberry.utils.stringToBlob and blobtoString dosen't work at all... i compiled the kitchenSink demo, but it didnt worked either. And no matter how many times you ask it, nobody'll answer, its like if no one check this forum at RIM.
03-13-2012 03:55 AM
Maybe we should open a bug report...
03-13-2012 10:38 AM
The only solution i'd found is an hibryd app, using a java applet for save and load data; using AIR web development tools, so you can acces flash classes, or creating an c++ aplication
03-13-2012 10:59 AM
03-16-2012 12:43 PM
Sorry, not sure how this thread was missed for so long.
I'm going to take a look and see if I can reproduce this. I did some testing with the blobToString function a few days ago and it seemed to be working, but I wasn't testing images. Can you let me know what it's failing on?
I think I've got plenty to go on for the stringToBlob function.
03-16-2012 03:11 PM
There is a similar thread here: http://supportforums.blackberry.com/t5/Web-and-Web
I will see what I can figure out to make this better.
03-17-2012 08:42 PM
Recently I worked on similar stuff and by lot of searching gathered the following.
Please note that base64 encoded data with its header is used for Canvas since the browser knows to decode the data as needed. However the image file like png has its own format and is mostly binary data.
To use as png , one needs to split out the data part like below.
1.
imgData = canvas.toDataURL("image/png");
var BASE64_MARKER = ';base64,';
var base64Index = imgData.indexOf(BASE64_MARKER) + BASE64_MARKER.length;
var base64 = imgData.substring(base64Index);
Then the encoded data needs to be converted to binary.
var raw = window.atob(base64);
2. One needs to find a way to save the binary data ( called raw above) as a file.
Most of the file APIs are meant for string with varous character encoding and do not handle binary data.
I think one needs to use the bytearray and get rid of the extra hex characters like C2 and C3 which are used by UTF-8 to show multibyte. There is a customFileWrite which may be enhanced to handle the binary stuff.
It helps a lot to use a hex editor to compare a real png file content and the data one is working on.