Is it possible to copy a canvas image to the clipboard?

前端 未结 4 637
难免孤独
难免孤独 2020-12-20 13:17

I\'ve created an image from my canvas object by using canvas.toDataURL(\"image/png\", 0.7). It works fine to save the image from the context menu but it doesn\'

4条回答
  •  感情败类
    2020-12-20 13:32

    Much easier 1 liner:
    Assuming u have a canvas.
    The following code will copy the canvas (as blob --> PNG image) to your clipboard.

        canvas.toBlob(blob => navigator.clipboard.write([new ClipboardItem({'image/png': blob})]));
    

提交回复
热议问题