gpt4 book ai didi

java - 缓冲图像 : How to certainly determine a pixel color

转载 作者:行者123 更新时间:2023-11-29 09:22:02 26 4
gpt4 key购买 nike

我有一张以 PNG 格式编码的位图。如何确定哪里是黑哪里是白?

            final int[] p = new int[1];
int iter = 0;
for (int i = 0; i < image.getWidth(); i++) {
for (int j = 0; j < image.getHeight(); i++) {
pixels[iter] = image.getData().getPixel(i, j, p)[0];
iter++;
}
}

总是每个像素返回 1。

最佳答案

BufferedImage image = ImageIO.read(file);
// Getting pixel color by position x=100 and y=40
int clr= image.getRGB(100,40);
int red = (clr & 0x00ff0000) >> 16;
int green = (clr & 0x0000ff00) >> 8;
int blue = clr & 0x000000ff;

红色、绿色和蓝色将是 x=100 和 y=40 处像素的 RGB 值

关于java - 缓冲图像 : How to certainly determine a pixel color,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5759371/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com