Access html5 canvas elements?

I used FileSaver.js on another project, here’s the code I used at the time:

var byteArray = bitmapData.encode (bitmapData.rect, new JPEGEncoderOptions (75));

#if html5
var buffer:ArrayBuffer = byteArray;
untyped window.saveAs (new Blob ([ buffer ], { type: "image/jpeg" }), "filename.jpg", true);
#else
var fileReference = new FileReference ();
fileReference.save (byteArray, "filename.jpg");
#end

and in the project.xml

<dependency path="Assets/FileSaver.min.js" if="html5" />

It should also work for PNG if you change the MIME type and encode with PNGEncoderOptions instead.

Looks like (maybe?) we could use FileReference to integrate this into OpenFL completely in the future

3 Likes