2014-02-10 2 views
-1

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]))); 
      } 

     } 
    } 
} 
+1

TYPE_INT_RGB에 A 부족 : TYPE_INT_ARGB를 사용하지 않는 이유는 무엇입니까? – slipperyseal

+0

더 많은 리소스를 사용하며 내 픽셀 배열에서도 작동하지 않습니다. 가능한 경우 RGB를 사용하고 싶습니다. –

+0

실제로 RGB는 32 비트 (4 바이트) 정수를 사용하며 ARGB와 같습니다. 그것은 단지 마지막 바이트를 사용하지 않습니다. 정사각형 못을 둥근 구멍에 밀어 넣는 것은 "자원 절약"으로 결코 정당화 될 수 없습니다. 만약 당신이 새로운 픽셀의 알파를 0xff로 설정해야 할 필요가 있기 때문에 작업이 느려지거나 더 복잡해지면 – slipperyseal

답변

0

알파를 사용할 수있는 방법이 있나요 : 스프라이트를 렌더링하는 데 사용

BufferedImage image = new BufferedImage(width/scale, height/scale, BufferedImage.TYPE_INT_RGB); 
int[] pixels = ((DataBufferInt)image.getRaster().getDataBuffer()).getData(); 

방법을

내가 지금까지 무엇을 가지고 INT_RGB을 사용하는 BufferedImage에 있습니까?

짧은 답변 : 제

긴 대답 : 아니, 형 INT_RGBBufferedImage 알파가 포함되어 있지 않습니다 (당신은, 즉 ... R, G 및 B의 의미를 재정의하지 않는 한). 는하지만 정확하게 알파 BufferedImage 다른 형태를 구성하는 것도 가능하다 (같은 TYPE_INT_ARGB, TYPE_4BYTE_ABGR 알파 또는 IndexColorModel 투명 화소 심지어 TYPE_BYTE_INDEXED) TYPE_INT_RGB를 사용 BufferedImage 상. 어쩌면 이것이 당신이하려는 일일까요?

사이드 노트 : Java2D는 이미 이미지 합성 및 다른 유형의 (Porter/Duff) 알파 혼합 규칙을 AlhpaComposite 클래스에 구현합니다. 이 클래스를 사용하면 하드웨어 가속 알파 블렌딩이 매우 빠릅니다. 왜 다시 구현해야하는지 이해가 안됩니다.