从 URL 解析图像像素坐标
Parse image pixel coordinates from URL
是否可以从 URL 解析图像的像素坐标?
可能使用变量和 forEach 记录每个像素坐标和当前像素索引的十六进制值?
var pixelcoord = foo..
var hexcolorofcoord = foo.
console.log(pixelcoord) //示例输出 = 123, 456
console.log(hexcolorofcoord) //示例输出=#fff000
使用 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.
}
}
}
}
是否可以从 URL 解析图像的像素坐标?
可能使用变量和 forEach 记录每个像素坐标和当前像素索引的十六进制值?
var pixelcoord = foo..
var hexcolorofcoord = foo.
console.log(pixelcoord) //示例输出 = 123, 456
console.log(hexcolorofcoord) //示例输出=#fff000
使用 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.
}
}
}
}