本文介绍了如何在具有透明度的java BufferedImage中读取像素颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在读取BufferedImage中的像素颜色,如下所示:

  ..... 
InputStream是=新的BufferedInputStream(conn.getInputStream());
BufferedImage image = ImageIO.read(is);

int color = image.getRGB(x,y);

int red =(colour& 0x00ff0000)>> 16;
int green =(color& 0x0000ff00)>> 8;
int blue =颜色& 0x000000ff;

现在,除了png具有透明性之外,此方法都可以正常工作。我发现如果x,y指的是没有颜色的透明像素,我仍会读取一种颜色,通常与图像中其他位置使用的颜色相同。



怎么办我检测到像素实际上是透明的而不是彩色的吗?



谢谢

解决方案
  int alpha =(colour>> 24)& 0xff; 

结果的取值范围也从0(完全透明)到255(完全不透明)。 / p>

I am reading pixel color in a BufferedImage as follows:

.....
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. 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.

How do I detect that the pixel is actually transparent and not colored?

Thanks

解决方案
int alpha = (colour>>24) & 0xff;

The result is also a value ranging from 0 (completely transparent) to 255 (completely opaque).

这篇关于如何在具有透明度的java BufferedImage中读取像素颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 23:07