gpt4 book ai didi

java - java中如何从灰度值中获取红绿蓝值?

转载 作者:行者123 更新时间:2023-11-30 08:48:19 26 4
gpt4 key购买 nike

我通过以下方式获取像素的灰度值:

val=img.getRGB(j, i) & 0xFF;

用于处理目的。

现在,在处理后我想要返回红色、绿色和蓝色值。我该怎么做?

最佳答案

下面是一些示例代码,用于获取 BufferedImage 上坐标 (x, y) 处像素的 r、g、b、alpha 和灰度值。

BufferedImage image;          // assume you have this image
int rgb = image.getRGB(x, y); // get the desired pixel
int r = (rgb >> 16) & 0xFF;
int g = (rgb >> 8) & 0xFF;
int b = (rgb & 0xFF);
int alpha = (rgb >> 24) & 0xFF;
int gray = (r + g + b) / 3; // rgb are not affected

关于java - java中如何从灰度值中获取红绿蓝值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32037776/

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