有什么办法在使用INT_RGB的BufferedImage
中使用alpha?我正在使用一维像素数组将精灵渲染到屏幕上,但我希望能够使用Alpha。有没有什么方法可以混合颜色,并在Photoshop中实现某种图层系统?Java:BufferedImage INT_RGB Alpha?
我一直在尝试通过混合颜色来创建一些自定义alpha,但我不太清楚该怎么做。
这是我到目前为止有:
的BufferedImage &像素阵列:
public static void drawSprite(Sprite sprite, int coord_x, int coord_y) {
int boundsX = (coord_x + sprite.width),
boundsY = (coord_y + sprite.height),
index = -1, pixels[] = Screen.pixels;
for(int y = coord_y; y < boundsY; y++) {
for(int x = coord_x; x < boundsX; x++) {
index++;
if(Screen.pixels[x + y * width] == 0) {
Screen.pixels[x + y * width] = sprite.pixels[index];
} else {
int[] screenPixel = intToARGB(Screen.pixels[x + y * width]);
int[] spritePixel = intToARGB(sprite.pixels[index]);
int[] newPixel = new int[4];
newPixel[0] = (screenPixel[0] + spritePixel[0])/2;
newPixel[1] = (screenPixel[1] + spritePixel[1])/2;
newPixel[2] = (screenPixel[2] + spritePixel[2])/2;
newPixel[3] = (screenPixel[3] + spritePixel[3])/2;
Screen.pixels[x + y * width] = Integer.parseInt((Integer.toString(newPixel[0]) +
Integer.toString(newPixel[1]) +
Integer.toString(newPixel[2]) +
Integer.toString(newPixel[3])));
}
}
}
}
注意TYPE_INT_RGB中缺少A :)为什么不使用TYPE_INT_ARGB? – slipperyseal
它使用了更多的资源,它也不适合我的像素阵列。我想尽可能使用RGB –
实际上,它不使用32位(4字节)整数,就像ARGB一样。它只是不使用最后一个字节。 “将资源节省下来”从来不合理地推动一个方形钉入圆孔。如果有的话,解决方法将变得更慢,更复杂 – slipperyseal