Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java:BuffereImage INT_RGB Alpha?_Java_Image Processing_Colors_Bufferedimage - Fatal编程技术网

Java:BuffereImage INT_RGB Alpha?

Java:BuffereImage INT_RGB Alpha?,java,image-processing,colors,bufferedimage,Java,Image Processing,Colors,Bufferedimage,在使用INT_RGB的BuffereImage中是否有任何方法可以使用alpha?我使用1D像素阵列在屏幕上渲染精灵,但我希望能够使用Alpha。有没有办法混合颜色,实现像photoshop那样的图层系统 我一直在尝试通过混合颜色来创建一些自定义alpha,但我也不太确定如何做到这一点 这就是我到目前为止所做的: BuffereImage和像素阵列: BufferedImage image = new BufferedImage(width / scale, height / scale, Bu

在使用INT_RGB的
BuffereImage
中是否有任何方法可以使用alpha?我使用1D像素阵列在屏幕上渲染精灵,但我希望能够使用Alpha。有没有办法混合颜色,实现像photoshop那样的图层系统

我一直在尝试通过混合颜色来创建一些自定义alpha,但我也不太确定如何做到这一点

这就是我到目前为止所做的:

BuffereImage和像素阵列:

BufferedImage image = new BufferedImage(width / scale, height / scale, BufferedImage.TYPE_INT_RGB);
int[] pixels = ((DataBufferInt)image.getRaster().getDataBuffer()).getData();
用于渲染精灵的方法:

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

        }
    }
}
publicstaticvoiddrawsprite(精灵精灵,int-coord\ux,int-coord\uy){
int boundsX=(坐标x+sprite.width),
boundsY=(坐标y+精灵高度),
索引=-1,像素[]=屏幕像素;
for(int y=coord_y;y
在使用
INT\u RGB
buffereImage
中是否有任何方法可以使用alpha

简短回答:没有

详细回答:不,类型为
INT\u RGB
buffereImage
不包含alpha(除非您重新定义R、G和B的含义,即…)。但是,当然可以将其他类型的
BufferedImage
与alpha(如
TYPE\u INT\u ARGB
TYPE\u 4BYTE\u ABGR
或甚至
TYPE\u BYTE\u index
IndexColorModel
中使用alpha或透明像素)正确组合到使用
TYPE\u INT\u RGB
BufferedImage上。也许这就是你想要做的


旁注:Java2D已经在类
AlhpaComposite
中实现了图像合成和不同类型的(波特/达夫)阿尔法混合规则。使用这个类,您可能会得到超快速的硬件加速alpha混合。我不明白您为什么要重新实现此功能。

请注意,在类型中缺少一个。\u INT\u RGB:)为什么不使用类型\u INT\u ARGB?它会占用更多资源,而且无法与我的像素阵列配合使用。如果可能的话,我想使用RGB,但我现在还不知道。我猜代码中最慢的部分是紧循环中的Integer.parseInt/Integer.toString。检查一下那个东西的移位。那个看起来都不正确。它没有正确地处理十六进制值。这可能就是为什么一切都是darkUse ARGB。RGB没有alpha。这就像询问如何在灰度图像中使用颜色。