我正在尝试更改像素的 alpha 值以使图像半透明。这是我的代码:
for(int x=0;x<image1.getWidth();x++) {
for(int y=0;y<image1.getHeight();y++) {
int rgb = image1.getRGB(x, y);
rgb = rgb | 0x000000ff; // make the image blue.
rgb = rgb & 0x33ffffff; // make the image transparent.
System.out.println("before: " + Integer.toHexString(rgb));
image1.setRGB(x, y, rgb);
int now_rgb= image1.getRGB(x, y);
System.out.println("after: " + Integer.toHexString(now_rgb));
}
}
输出是这样的:
before: 331b1aff
after: ff1b1aff
before: 331918ff
after: ff1918ff
before: 331e1bff
after: ff1e1bff
before: 332623ff
after: ff2623ff
before: 332e29ff
after: ff2e29ff
如您所见,setRGB 似乎省略了 alpha 值并将其设置为“ff”。我该如何解决这个问题,为什么会首先发生?