Video Thumbnail

Sign up for a plan to instantly unlock all premium lessons.

UNLOCK LESSON

Premium Features

Download Video

Sampling Images

Sampling images with a canvas element requires a bit of know-how around how images are technologically rendered.

If we analyze an image being displayed on a screen, looking very closely (or very zoomed in), you’ll see the image is composed of many little pixels that when used together, form the whole image.

To sample and manipulate an image with canvas, we must loop over every pixel within an image, and store its color data within a canvas object we can interact with. Once you get through this process, you’ll be able to manipulate your image in an unlimited number of ways that just wouldn’t be possible otherwise.

Comments

Want to participate?

Create a free Chris Courses account to begin

Login
XxCFxX posted 4 years ago

Hey Chris! I Seem To Be Having An Issue Uploading The Image! I Got This Error At 1:16 In The Video.

Error:

(anonymous) @ (index):14

localhost/:1 Access to image at 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/35418/charizard.png' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

0
chris posted 4 years ago

Hmm, CORS can always be a bit of a pain. I think your best bet here would be to download the file locally and to reference it from your project directly. That would immediately take care of any CORS issues since there wouldn't be any cross origin requests being made.

Let me know if that makes sense and if you need any help.

0
XxCFxX posted 4 years ago

Hmmm...

GET http://localhost:3000/charizard.png 404 (Not Found)

0
chris posted 4 years ago

Would you be able to shoot me a Git repo? Will def be able to pinpoint the issue and get you going with that.

0
XxCFxX posted 4 years ago

yea sure, lemme remake it rq

0
d
dshhh posted 5 years ago

Your html code doesn't reference the canvas and there are a bunch of other files in the folder like a readme so I assume there's some framework you built it with? Is there some missing video? The project looks really cool, but I want to be able to follow along, not have to figure things out for myself here.

Thanks! Love your work.

1
chris posted 5 years ago

Hey sorry! Bit of an older vid - I can make sure to put the exact code in here for download and viewing, just give me an a few hours and I’ll have it up 🙌

0
chris posted 5 years ago

So looking through this vid a bit further, it does indeed look like I used webpack to compile and read my JS automatically. I just inserted some code into the video description which should do away with the need to use any bundler—just recreate those files, run index.html and you should be good to go.

The code at this point animates the Charizard image and all of its pixels to the right of the screen as shown in the end of the video. Let me know if you need any additional code, I'm working on a downloadable version to attach to the video now.

1
d
dshhh posted 5 years ago

Thanks, this gave an error too but I fixed it by adding the Dot stuff into the canvas.js file and removing the "export default" part.

The error said something about modules.

1
chris posted 5 years ago

Might require some sort of module bundler to use ES6 import / export features. Sorry about the issues, glad you were able to get it going though, I’ll make note in the description based off your feedback. Thanks!

1
d
dshhh posted 5 years ago

Never used a module bundler on my own. I come from a vanilla javascript/html spaghetti coding background. Thanks!

1

Providing the lift to launch your development career

© 2026 Chris Courses. All rights reserved.