javascript - Highcharts: saving canvas image as local file in IE -



javascript - Highcharts: saving canvas image as local file in IE -

i'm trying code javascript function takes highcharts image, converts canvas, , downloads file image locally (without going server).

my problem ie. tried using mssaveblob blob , msblobbuilder; in first case file downloads content wrong (the image damaged when opened).

fist code uses blob/mssaveblob (see jsfiddle, run ie):

var image = canvas.todataurl("image/jpeg"); if (navigator.mssaveblob) { homecoming navigator.mssaveblob(new blob([image],{type:"image/jpeg"}),"file23.jpeg"); }

second code uses msblobbuilder/mssaveblob doesn't generate file (see jsfiddle, run ie):

var image = canvas.todataurl("image/jpeg"); if (window.msblobbuilder) { var bb = new msblobbuilder(); bb.append(image); homecoming navigator.mssaveblob(bb, "file24.jpeg"); }

any ideas how create of these work? there preferred method? understand work ie10+ only.

todataurl produces base64 string of png. need raw info (or blob), though.

from link:

by using canvas.todataurl(), preclude possibility of using application view saved drawing. saving drawing png file has benefit of allowing number of standard applications, including browser, display drawing. switching canvas.mstoblob(), can save file straight png...

so:

canvg(canvas, svg); image = canvas.mstoblob(); if (navigator.mssaveblob) { homecoming navigator.mssaveblob(new blob([image], {type:"image/png"}),"file23.png"); }

update fiddle.

edits

for more universal way convert base64 images blobs see reply here.

and illustration of how in workflow:

var image = canvas.todataurl( "image/jpeg" ); image = b64toblob(image.replace("data:image/jpeg;base64,",""),"image/jpeg") if (navigator.mssaveblob) { homecoming navigator.mssaveblob(image,"file23.jpeg"); }

javascript highcharts

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -