Разобрать пиксельные координаты изображения по URL - PullRequest
0 голосов
/ 20 октября 2019

Можно ли проанализировать пиксельные координаты изображения из URL-адреса?

Возможно записать каждую пиксельную координату и шестнадцатеричное значение этого текущего пиксельного индекса с помощью переменных и forEach?

var pixelcoord =foo ..

var hexcolorofcoord = foo.

console.log (pixelcoord) // пример вывода = 123, 456

console.log (hexcolorofcoord) // пример вывода= # fff000

1 Ответ

0 голосов
/ 24 октября 2019

Решено с помощью MarvinJ.

image = new MarvinImage();
image.load("https://i.imgur.com/2sGyojB.png", imageLoaded);

function imageLoaded() {

for (var y = 0; y < image.getHeight(); y++) {
    for (var x = 0; x < image.getWidth(); x++) {
        var red = image.getIntComponent0(x, y);
        var green = image.getIntComponent1(x, y);
        var blue = image.getIntComponent2(x, y);
        var alpha = image.getAlphaComponent(x, y);
        var RBGCOLOR = "rgb(" + red + "," + green + "," + blue + ")";

        var HexColor = red.toString(16) + green.toString(16) + blue.toString(16)

        if (HexColor === "ffffff") {
            console.log("White") // If it's a white pixel, log
        } else {
            console.log(HexColor) // Log the hex color.
            console.log(x + " : " + y) // Log the X & Y coordinates for each pixel.
        }

    }
}
}
...