HTML5 Canvas - Make and Image Black and White

preview_player
Показать описание
Using canvas we can write very little code to convert and image into black white. Really all you need to do is use the formular R*.3 + G*.59 + B*.11 and store that as each pixel.

In actuality you could use any numbers as long as you store each sub pixel as the same value it will be black and white
Рекомендации по теме
Комментарии
Автор

its grabbing the pixel data, and taking the saturation down for each pixel. Each pixel is made up of RGB and there are calculations one can do to an RGB value to take out the color and leave just the shades. Convert RGB to HSL then take the S to 0. convert it back to RGB and you get your values.

optikalefx
Автор

Yea I can do that. Thanks for the suggestion!

optikalefx
Автор

awesome tutorial!!
pardon me if it is a stupid question but how did the rgba image appear too even when you converted it to grayscale and populated it back to (0, 0) coordinates?
i thought only the grayscale image was suppose to appear after you read each pixel of the original image and converted it to grascale and moved it back to the array.

kushanav
Автор

it's not really 160000.
It's 160000 singe pixels, but imageData.data array contains 4 additional entries for each of them so array length is 160000x4 = 640000 and that is the value which you'll get by

vovegde
Автор

Can you make a video on how the greyscaled image transforms into the real image when mouse hover?

VirtousOn
Автор

on chrome I get this error: Unable to get image data from canvas because the canvas has been tainted by cross-origin data.
Uncaught Error: SECURITY_ERR: DOM Exception 18

Zoske
Автор

How can we change the color of image to any other color lets say green? I mean the whole image becomes green image or any other color user wants.

doforumda
Автор

What did you say you were using as your web server?

joeBalt