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
Highlighted
New Contributor
Posts: 6
Registered: ‎02-23-2012
My Device: PlayBook
My Carrier: ATT
Accepted Solution

stringToblog save image problem

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

New Contributor
Posts: 6
Registered: ‎02-23-2012
My Device: PlayBook
My Carrier: ATT

Re: stringToblog save image problem

Anybody have anything on this?  I have tried a million things with no luck, I am following what was discussed in other threads and what is in the documentation for webworks.  I have to believe somebody can point me in a direction. Or tell me that theplaybook just can not do this at this time.  It does state it should work in the 2.2 sdk which is what i am using... 

 

Sorry if i sound brash... it is so frustrating to be so close and you know this type of functionality should be there somewhere...

Developer
Posts: 275
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: stringToblog save image problem

Hi. Same problem for me. Saved images are not valid. I'm still looking for a way to save canvas to image files...

Twitter : @LaurentKP
My apps
New Developer
Posts: 26
Registered: ‎03-06-2012
My Device: playbook
My Carrier: 8298611647

Re: stringToblog save image problem

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.  

Developer
Posts: 275
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: stringToblog save image problem

Maybe we should open a bug report...

Twitter : @LaurentKP
My apps
New Developer
Posts: 26
Registered: ‎03-06-2012
My Device: playbook
My Carrier: 8298611647

Re: stringToblog save image problem

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

Developer
Posts: 275
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: stringToblog save image problem

You are right, but it's a bit complicated for me. Because I need to save the whole PlayBook screen, I have a workaround : ask users to make a screenshot with + and - buttons...
Twitter : @LaurentKP
My apps
Retired
Posts: 856
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: stringToblog save image problem

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.

Tim Windsor
Open Source Technical Lead
Retired
Posts: 856
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: stringToblog save image problem

There is a similar thread here: http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/ReadFile-and-data-manipulation/t...

 

I will see what I can figure out to make this better.

Tim Windsor
Open Source Technical Lead
New Contributor
Posts: 7
Registered: ‎02-19-2012
My Device: Rim Playbook
My Carrier: Roger

Re: stringToblog save image problem

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.