[英]When I Read a Image Pixel the pixel Alpha is always 255
In the following code example I set an Image pixel Alpha value to 70 but when I extract it again I get 255. Am I extracting it wrong or setting it wrong? 在下面的代码示例中,我将图像像素Alpha值设置为70,但是当再次提取它时,我得到255。我提取错误还是设置错误? what am I missing or not understanding.
我缺少或不了解的内容。
public void createImage()
{
BufferedImage img = new BufferedImage(2, 2,
BufferedImage.TYPE_INT_RGB);
//Set Pixel
int red = 50;
int green = 10;
int blue = 100;
int alpha = 70;
int col = (alpha << 24) | (red << 16) | (green << 8) | blue;
img.setRGB(0, 0, col); //Set pixel 0,0
//Read Pixel
int colint = img.getRGB(0, 0); //Get pixel 0,0
Color newCol = new Color(colint,true);
int alphaToPrint = newCol.getAlpha();
int redToPrint = newCol.getRed();
int greenToPrint = newCol.getGreen();
int blueToPrint = newCol.getBlue();
System.out.println("redToPrint :" +String.valueOf(redToPrint));
System.out.println("greenToPrint :" +String.valueOf(greenToPrint));
System.out.println("blueToPrint :" +String.valueOf(blueToPrint));
System.out.println("alphaToPrint :" +String.valueOf(alphaToPrint));
}
The result when running the code : 运行代码的结果:
What I expected is to get 70 when reading the alpha value : 我预期在读取alpha值时会得到70:
int alphaToPrint = newCol.getAlpha();
Please help. 请帮忙。
Your BufferedImage
has no alpha channel ( TYPE_INT_RGB
) 您的
BufferedImage
没有Alpha通道 ( TYPE_INT_RGB
)
Use BufferedImage.TYPE_INT_ARGB
instead (note the 'A') 请改用
BufferedImage.TYPE_INT_ARGB
(注意“ A”)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.