[英]How to read pixel color in a java BufferedImage with transparency
I am reading pixel color in a BufferedImage as follows:我正在读取 BufferedImage 中的像素颜色,如下所示:
.....
InputStream is = new BufferedInputStream(conn.getInputStream());
BufferedImage image = ImageIO.read(is);
int color = image.getRGB(x, y);
int red = (colour & 0x00ff0000) >> 16;
int green = (colour & 0x0000ff00) >> 8;
int blue = colour & 0x000000ff;
Now this works fine except for png's with transparency.现在这工作正常,除了透明的 png。 I find that if x,y refer to a transparent pixel with no color, i still read a color, generally the same color as used elsewhere in the image.
我发现如果 x,y 指的是一个没有颜色的透明像素,我仍然会读取一种颜色,通常与图像中其他地方使用的颜色相同。
How do I detect that the pixel is actually transparent and not colored?如何检测像素实际上是透明的而不是彩色的?
Thanks谢谢
int alpha = (colour>>24) & 0xff;
结果也是一个范围从 0(完全透明)到 255(完全不透明)的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.