Created
September 19, 2018 20:41
-
-
Save redblobgames/d5d1e61c68e29bed96c8cb728db54f93 to your computer and use it in GitHub Desktop.
Remove alpha channel on a canvas, so it's always transparent or always opaque
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
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height); | |
const pixels = imageData.data; | |
for (let i = 3, n = canvas.width * canvas.height * 4; i < n; i += 4) { | |
pixels[i] = pixels[i] < 127? 0 : 255 | |
} | |
ctx.putImageData(imageData, 0, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! 🔥