Save HTML 5 canvas to a file in Chrome?

前端 未结 2 781
难免孤独
难免孤独 2021-02-14 07:09

Save PNG (etc.) work in this demo in Firefox, but not Chrome.

Convert to PNG (etc.) work in Firefox and Chrome.

Is there a way *in Chrome* to save an image of a

2条回答
  •  时光取名叫无心
    2021-02-14 07:28

    The simplest way to do it is to use the toDataURL() function.

    Say you have a canvas:

    var canvas =  document.getElementById("myCanvas");
    

    Then, with a button with id "saveButton", you can make it pop open a new window with the canvas as a png, and the user can save that page.

    document.getElementById("saveButton").onClick = function() {
        window.open(canvas.toDataURL());
    }
    

提交回复
热议问题