【问题标题】:Parse image pixel coordinates from URL从 URL 解析图像像素坐标
【发布时间】:2020-02-16 14:31:49
【问题描述】:

是否可以从 URL 解析图像的像素坐标?

可能使用变量和 forEach 记录每个像素坐标和当前像素索引的十六进制值?

var pixelcoord = foo..

var hexcolorofcoord = foo.

console.log(pixelcoord) //示例输出 = 123, 456

console.log(hexcolorofcoord) //示例输出 = #fff000

【问题讨论】:

  • 那么,对于每个像素,我如何记录该像素的坐标和十六进制颜色。
  • 绝对有可能!看看 HTML 画布。请参阅 herehere 了解开始。也许有人会在这个时候有脑力写出更全面的答案。祝你好运!

标签: javascript jquery tampermonkey


【解决方案1】:

使用 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.
        }

    }
}
}

【讨论】:

    猜你喜欢
    • 2013-04-22
    • 2023-04-06
    • 2021-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-26
    • 1970-01-01
    • 2013-09-26
    相关资源
    最近更新 更多