Created
July 23, 2020 07:47
-
-
Save av01d/24f4554274d100e8e9a5ea8ae10e1b78 to your computer and use it in GitHub Desktop.
Javsacript: Convert canvas to image, image to canvas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function convertImageToCanvas(image) { | |
var canvas = document.createElement("canvas"); | |
canvas.width = image.width; | |
canvas.height = image.height; | |
canvas.getContext("2d").drawImage(image, 0, 0); | |
return canvas; | |
} | |
function convertCanvasToImage(canvas) { | |
var image = new Image(); | |
image.src = canvas.toDataURL("image/png"); | |
return image; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment