Pan*_*nos 8 java transparency bufferedimage
我将使用BufferedImage的getRGB方法.我想检查图像的像素,看看哪些像素具有透明度(一般来说,我将拥有的透明像素将完全透明).如何从getRGB返回的int中获取它?
chu*_*ubs 18
BufferedImage img = ....
public boolean isTransparent( int x, int y ) {
int pixel = img.getRGB(x,y);
if( (pixel>>24) == 0x00 ) {
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
当然,img必须采用正确的格式TYPE_4BYTE_ABGR或某种支持alpha通道的格式,否则将始终是不透明的(即0xff).