1 thought on “How do I get the pixel color of a jpg?

  1. I think should be something like this:

    function getImageData( image ) {
    
        var canvas = document.createElement( 'canvas' );
        canvas.width = image.width;
        canvas.height = image.height;
    
        var context = canvas.getContext( '2d' );
        context.drawImage( image, 0, 0 );
    
        return context.getImageData( 0, 0, image.width, image.height );
    
    }
    
    function getPixel( imagedata, x, y ) {
    
        var position = ( x + imagedata.width * y ) * 4, data = imagedata.data;
        return { r: data[ position ], g: data[ position + 1 ], b: data[ position + 2 ], a: data[ position + 3 ] };
    
    }
    
    var imagedata = getImageData( imgTexture.image );
    var color = getPixel( imagedata, 10, 10 );

Comments are closed.