Canvas - Images and Image Data - Episode 4

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ก.ย. 2024
  • This is the fourth video in the Learning Canvas series
    This tutorial focuses on how you can place images on the canvas, crop images, extract image data, show and hide colour channels, or convert images to greyscale.
    Code GIST: gist.github.co...
    Canvas Video Playlist - • Learning HTML5 Canvas ...

ความคิดเห็น • 63

  • @flwi
    @flwi 5 ปีที่แล้ว +6

    Nice, you just showed how I could solve my problem. Made my day! Thanks for your great tutorial!

  • @hk20092009able
    @hk20092009able 5 ปีที่แล้ว +2

    I am cleanly understanding. Something I had thought is very difficult, you are my hero

  • @TenthFir
    @TenthFir 8 หลายเดือนก่อน

    Simple and to the point. Love it ..

  • @jimbo2849
    @jimbo2849 4 ปีที่แล้ว

    Only current working TH-cam tutorial! Ty

  • @havefun5519
    @havefun5519 2 ปีที่แล้ว

    Good video, nice voice and speed. Thanks

  • @kyunghwankim1269
    @kyunghwankim1269 3 ปีที่แล้ว

    Very nice tutorial! Thank you 👍

  • @kukusikibabasikitv
    @kukusikibabasikitv 3 ปีที่แล้ว

    Thanks a lot! Great lesson 🐱

  • @IDMarketer
    @IDMarketer ปีที่แล้ว

    Hi sir, thank you so much for the tutorial, the datatoUrl (the variable img) it should be saved as array right?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  ปีที่แล้ว

      The return value from canvas.toDataURL( ) is a string.
      The string can be used as a src value for any image element. It's called a data url because it starts with "data:" instead of "http:" or "https:"

  • @MotiviqueStudio
    @MotiviqueStudio 2 ปีที่แล้ว +1

    Great video. I'm curious if in addition to these effects you can simply draw on top of the image? For instance, if you import the image of a coloring book.

  • @buzzer79
    @buzzer79 3 ปีที่แล้ว

    hi, by the way you cant update the imgData.data because its read only. so just pass the imgData into the ctx.putImageData(imgData, 0, 0); like this and it will work

  • @youzarsef6184
    @youzarsef6184 3 ปีที่แล้ว

    Hello Sir, Your Videos are very good and usefull, but i have a request , if you make a video of (How to Take Screenshot of a Div) with pure Javascript no library use), it will be so nice of you, I am waiting for your kind reply. Thanks

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 ปีที่แล้ว

      Please add any tutorial requests in the comments here - th-cam.com/video/LCezax2uN3c/w-d-xo.html

  • @dazikenhd364
    @dazikenhd364 3 ปีที่แล้ว

    Hi, How do i draw an image onto the canvas from a folder within my source folder in the most basic way? Ive tried other solutions but they didn't work. Any solutions?
    This is my code:
    function drawChessBoard(canvas) {
    const c = document.getElementById("board");
    const ctx = c.getContext("2d");

    var piece = new Image();
    piece.src = './wrook.png';
    ctx.drawImage(piece, 60, 60, 60, 60);

    }

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 ปีที่แล้ว

      The video shows the most basic way to load images.
      When you load an image though you need to wait for the image load event before you can call the drawImage method.

    • @dazikenhd364
      @dazikenhd364 3 ปีที่แล้ว +1

      @@SteveGriffith-Prof3ssorSt3v3 I was following your code, its fine now. Silly me made a simple error mistake that I didn't spot... :D

  • @boristherin4104
    @boristherin4104 3 ปีที่แล้ว

    thx, trying to deal with getImageData to scroll any images without adding a twin one for the loop
    btw, if anyone may want to download that image (with button or auto) :
    let link = document.createElement('a');
    link.href = canvas.toDataURL();
    link.download = 'download.jpg'; // or ur own filename
    link.click();
    link.delete();

  • @waleedsharif618
    @waleedsharif618 2 ปีที่แล้ว

    Could you make a tutorial of canvas(reactjs) where is zoom in and zoom out functionality, for example in canvas there is a photo and on that photo there is two buttons one for zoom in and one for zoom out

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 ปีที่แล้ว

      Please post any tutorial requests in the comments here - th-cam.com/video/LCezax2uN3c/w-d-xo.html

  • @omkargaidhani287
    @omkargaidhani287 4 ปีที่แล้ว

    Thanks
    Can you share how to show tiff images in angular as Chrome browser doesn't support,

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 ปีที่แล้ว

      Browsers do not support tiff images. Only svg, png, jpg, gif, and to a lesser extend webp.

  • @supriyashah3863
    @supriyashah3863 3 ปีที่แล้ว

    I'm trying to draw image of array using angular... I didn't find any way to draw multiple canvas dynamically in angular

  • @shahanahmed9444
    @shahanahmed9444 3 ปีที่แล้ว

    the image drawn on the canvas is blurry compared to the original photo.. any ideas why?

  • @pondokkoding5023
    @pondokkoding5023 8 หลายเดือนก่อน

    how about picture in picture overlay?

  • @aleki_x
    @aleki_x 3 ปีที่แล้ว

    Heyy Steve!
    Have a way to make a filter and "remove" only ONE color in the image?
    Like, I want to put a draw and remove the background. Can I did it using canvas?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 ปีที่แล้ว +1

      You can loop through the Canvas image data and you will have access to the value for each of the Red, Green, and Blue channels. You can set one of those values to zero and then set the data back to the Canvas.

    • @aleki_x
      @aleki_x 3 ปีที่แล้ว

      @@SteveGriffith-Prof3ssorSt3v3 do you have any tutorial about it to show me? Or another site/channel. I'll love it! And thank for your answer, love your channel : )

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 ปีที่แล้ว

      All my Canvas videos are in this playlist - th-cam.com/video/uh1Sgj2Gt70/w-d-xo.html

  • @biswamohandwari780
    @biswamohandwari780 3 ปีที่แล้ว

    Can you please make a video on the Selection API in Js

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 ปีที่แล้ว

      Please post any tutorial requests in the comments here - th-cam.com/video/LCezax2uN3c/w-d-xo.html

  • @Snoo29293
    @Snoo29293 3 ปีที่แล้ว

    When I try to use getImageData() on a canvas with an image I get a security error, because of CORS, even though I do not use an image from another domain, I have the image downloaded in my file.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 ปีที่แล้ว +1

      The origin of the html file that contains the Canvas must be exactly the same as the image. Protocol, domain, and port all must match.

    • @Snoo29293
      @Snoo29293 3 ปีที่แล้ว

      @@SteveGriffith-Prof3ssorSt3v3 how can I make them match?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 ปีที่แล้ว +1

      @@Snoo29293 they just have to come from the same origin. Whatever is in the location bar of the browser needs to be the same as the image origin

    • @Snoo29293
      @Snoo29293 3 ปีที่แล้ว

      @Sam Marsh I used a live server, if you use a local server then you get the error.

    • @Snoo29293
      @Snoo29293 3 ปีที่แล้ว

      @Sam Marsh also, if you are taking an image from another place such as google drive or Dropbox set image.crossorigin to "anonymous". To get a live server you can simple download live server extension in visual studio code.

  • @alexdin1565
    @alexdin1565 2 หลายเดือนก่อน

    can do the same with videos?

  • @stickguy9109
    @stickguy9109 3 ปีที่แล้ว

    Can you explain how to know if all images(and other assets) finished loading and then execute a function

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 ปีที่แล้ว +1

      Any file that you load into the browser has a built-in load event that you can use to trigger a function. If you have an array of assets to load you can just wait until all of them load by counting each as it loads.

    • @stickguy9109
      @stickguy9109 3 ปีที่แล้ว

      @@SteveGriffith-Prof3ssorSt3v3 Thanks for your attentionbut I already tried this and it shows ```assets[i].addEventListener``` is not a function. And i have urls to images in the assets array.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 ปีที่แล้ว +1

      @@stickguy9109 The listeners have to be added to the HTML elements, not to URLs. URLs are just strings. Strings can't have listeners.

    • @stickguy9109
      @stickguy9109 3 ปีที่แล้ว +1

      @@SteveGriffith-Prof3ssorSt3v3 Thank you I will try asking Stackoverflow

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 ปีที่แล้ว +2

      @@stickguy9109 I have a playlist on events that explains how event listeners work, including the load listener.

  • @ironmanlifts
    @ironmanlifts 4 ปีที่แล้ว

    Thanks, I love your videos very informative. Do you think it's a possible, practical, or a good idea to save canvas in localStorage / chrome storage ? Maybe using json stringify parse. For example an extension that displays certain images depending on xzy criteria ? Assuming the extension is unlimited storage and not many images are going to be stored. I know I can create a folder called images , i was just wondering if it was possible or a good idea to save canvas in storage.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 ปีที่แล้ว +3

      You can extract images as base 64 from the canvas and save them in localstorage but you need to keep in mind a few things. Users can delete the contents of localstorage. Base64 images are much bigger than their binary versions. You are limited, depending on the browser, to about 20MB typically per domain. So, think 2 to 5 images depending on the size

    • @ironmanlifts
      @ironmanlifts 4 ปีที่แล้ว +1

      Steve Griffith Thanks I appreciate it. Love your videos I watch them and recommend them all the time.

  • @eric7758
    @eric7758 5 ปีที่แล้ว

    Thanks so much is there away i can do blur on certain areas/ parts in the image?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  5 ปีที่แล้ว +1

      If you can do the math, we have access to the 4 color channels on every pixel. You can loop through the pixels calculating the colour changes and updating the image.
      Other than that, You can apply a CSS blur filter to the whole canvas element.

    • @eric7758
      @eric7758 5 ปีที่แล้ว

      @@SteveGriffith-Prof3ssorSt3v3 Thanks will try that out

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  5 ปีที่แล้ว +1

      @@eric7758 Here is my video on the CSS filters - th-cam.com/video/fmSHNItOBpg/w-d-xo.html

  • @nehashubh2702
    @nehashubh2702 3 ปีที่แล้ว

    Can you help me sir

  • @Felipekimst
    @Felipekimst 2 ปีที่แล้ว

    I get a cors problem here

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 ปีที่แล้ว +1

      CORS applies any time you load something from a different domain. If you load an image from a different domain, without the access-control-allow-origin header from the server then the browser will not let you use the image on a canvas.

    • @Felipekimst
      @Felipekimst 2 ปีที่แล้ว

      @@SteveGriffith-Prof3ssorSt3v3 it isnt possible to do it on file:// right?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 ปีที่แล้ว

      @@Felipekimst no. Fetch will not load from file:///