INT_RGB를 사용하는 BufferedImage
에서 알파를 사용할 수 있습니까? 화면에 스프라이트를 렌더링하기 위해 1D 픽셀 배열을 사용하고 있지만 알파를 사용할 수 있기를 원했습니다. 색상을 혼합하고 포토샵과 같은 레이어 시스템을 만들 수있는 방법이 있습니까?자바 : BufferedImage INT_RGB 알파?
색상을 혼합하여 맞춤 알파를 만들려고했지만 그 방법을 잘 모르겠습니다.
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를 사용하고 싶습니다. –
실제로 RGB는 32 비트 (4 바이트) 정수를 사용하며 ARGB와 같습니다. 그것은 단지 마지막 바이트를 사용하지 않습니다. 정사각형 못을 둥근 구멍에 밀어 넣는 것은 "자원 절약"으로 결코 정당화 될 수 없습니다. 만약 당신이 새로운 픽셀의 알파를 0xff로 설정해야 할 필요가 있기 때문에 작업이 느려지거나 더 복잡해지면 – slipperyseal