Question

Im trying to figure out how to save a image/canvas to a local folder in Smart Mobile Studio. This should be the way to create a right-click save to folder event:

var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
   // draw .................

   // save canvas image as data url (png format by default)
var dataURL = canvas.toDataURL();
   // set canvasImg image src to dataURL so it can be saved as an image
document.getElementById('canvasImg').src = dataURL;

I expect the sms-way to be something like this:

W3Cont:=TW3GraphicContext.Create(Null);
W3Cont.Allocate(300,300);
W3Canv:=TW3Canvas.Create(W3Cont);
asm
  var dataURL = @W3Canv.toDataURL();
  document.getElementById('canvasImg').src = dataURL;
end; 

But the toDataUrl is unknown to sms !? ...

Était-ce utile?

La solution

When I look in W3Graphics.pas, I see that TCanvas has a ToDataURL function. So you can use this function without the asm section, like

var dataURL := W3Canv.ToDataURL('');

(note: javascript within an asm section is case sensitive!)

You can also take a look at W3Image.pas and it's TW3Image.toDataUrl function

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top