透明度Java BuffereImage如何知道像素是否透明 1 年 Questions & Answers 9266 我将使用BuffereImage的getRGB方法。我想检查一幅图像的像素,看看它们中哪些是透明的(通常我将拥有的透明像素将是完全透明的)。如何从getRGB返回的int中获取它
# 1 楼答案 BufferedImage img = .... public boolean isTransparent( int x, int y ) { int pixel = img.getRGB(x,y); if( (pixel>>24) == 0x00 ) { return true; } return false; } 当然,img必须采用正确的格式类型_4BYTE_ABGR或支持alpha通道的某种格式,否则if将始终是不透明的(即0xff)
# 1 楼答案
当然,img必须采用正确的格式类型_4BYTE_ABGR或支持alpha通道的某种格式,否则if将始终是不透明的(即0xff)
# 2 楼答案
在int中获得alpha值的正确移位是>>>;由于符号位
例如: int alpha1=(像素1&;0xff000000)>>>;24;