Saving canvas as a PNG or JPG

后端 未结 3 1957
无人共我
无人共我 2021-02-01 20:09

I want to save canvas as PNG, without opening it in a new window as base64-encoded image.

I used this code:

jQuery(\"#btnPreview\").click(function(){
            


        
3条回答
  •  死守一世寂寞
    2021-02-01 20:46

    canvas.toDataURL('png') provides a string a la data:image/png;base64,XYZ. You could stuff that into an download (possibly trigger a click event on the element). See Downloading resources in HTML5: a[download]

    Currently supported only by Google Chrome, though.

提交回复
热议问题