Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/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中隔离红/绿/蓝通道_Java_Image Processing_Colors_Bufferedimage_Color Channel - Fatal编程技术网

在Java BuffereImage中隔离红/绿/蓝通道

在Java BuffereImage中隔离红/绿/蓝通道,java,image-processing,colors,bufferedimage,color-channel,Java,Image Processing,Colors,Bufferedimage,Color Channel,如何在BuffereImage中隔离红色/绿色/蓝色通道:我有以下代码无法工作:` public static BufferedImage isolateChannel(BufferedImage image, EIsolateChannel channel) { BufferedImage result=new BufferedImage(image.getWidth(), image.getHeight(), image

如何在BuffereImage中隔离红色/绿色/蓝色通道:我有以下代码无法工作:`

public static BufferedImage isolateChannel(BufferedImage image,
        EIsolateChannel channel)
{
    BufferedImage result=new BufferedImage(image.getWidth(),
            image.getHeight(),
            image.getType());
    int iAlpha=0;
    int iRed=0;
    int iGreen=0;
    int iBlue=0;
    int newPixel=0;

    for(int i=0; i<image.getWidth(); i++)
    {
        for(int j=0; j<image.getHeight(); j++)
        {
            iAlpha=new Color(image.getRGB(i, j)).getAlpha();
            iRed=new Color(image.getRGB(i, j)).getRed();
            iGreen=new Color(image.getRGB(i, j)).getGreen();
            iBlue=new Color(image.getRGB(i, j)).getBlue();

            if(channel.equals(EIsolateChannel.ISOLATE_RED_CHANNEL))
            {
                newPixel=iRed;
            }

            if(channel.equals(EIsolateChannel.ISOLATE_GREEN_CHANNEL))
            {
                newPixel=iGreen;
            }

            if(channel.equals(EIsolateChannel.ISOLATE_BLUE_CHANNEL))
            {
                newPixel=iBlue;
            }

            result.setRGB(i,
                    j,
                    newPixel);
        }
    }

    return result;
}`
公共静态缓冲区映像隔离通道(缓冲区映像、,
艾索拉海峡
{
BuffereImage结果=新的BuffereImage(image.getWidth(),
image.getHeight(),
image.getType());
int iAlpha=0;
int iRed=0;
int-iGreen=0;
int-iBlue=0;
int newPixel=0;

对于java中的(int i=0;i
Color
)是在压缩整数中定义的,即在32位整数中,前8位是alpha,后8位是红色,后8位是绿色,后8位是蓝色

假设下面是一个表示颜色的32位整数

AAAAAAAA RRRRRRRR GGGGGGGG BBBBBBBB
^Alpha   ^Red     ^Green   ^Blue
也就是说,alpha、红色、绿色和蓝色基本上都是8位,值从0到255(颜色范围)。因此,当您想要将这些单独的组件组合回32位整数颜色时,您应该写入

color=alpha试试这个:

int width = bufferedImage.getWidth(), height = bufferedImage.getHeight();
Object dataElements = null;
Raster raster = bufferedImage.getRaster();
ColorModel colorModel = bufferedImage.getColorModel();
int red, blue, green, alpha;
for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) {

        dataElements = raster.getDataElements(x, y, dataElements);
        // extract colors
        red   = colorModel.getRed(dataElements);
        blue  = colorModel.getBlue(dataElements);
        green = colorModel.getGreen(dataElements);
        alpha = colorModel.getAlpha(dataElements);
    }
}
int-width=bufferedImage.getWidth(),height=bufferedImage.getHeight();
对象数据元素=null;
光栅=buffereImage.getRaster();
ColorModel ColorModel=BuffereImage.getColorModel();
int红色、蓝色、绿色、阿尔法色;
对于(int y=0;y
Hmm,很好的导师,非常感谢,但现在我加载了一些图像,当我应用颜色过滤器时,我得到的图像充满了该颜色-图像不相似,我得到彩色矩形(如果我选择红色过滤器,我得到图像大小的红色矩形,如果我选择绿色过滤器,我得到绿色矩形,蓝色过滤器的情况也一样)
newPixel=0; //Add this line
iAlpha=new Color(img.getRGB(x, y)).getAlpha();
iRed=new Color(img.getRGB(x, y)).getRed();
iGreen=new Color(img.getRGB(x, y)).getGreen();
iBlue=new Color(img.getRGB(x, y)).getBlue();
int rgb = img.getRGB(x,y);
iAlpha = rgb>>24 & 0xff;
iRed = rgb >>16 & 0xff;
iGreen = rgb>>8 & 0xff;
iBlue = rgb & 0xff;
int width = bufferedImage.getWidth(), height = bufferedImage.getHeight();
Object dataElements = null;
Raster raster = bufferedImage.getRaster();
ColorModel colorModel = bufferedImage.getColorModel();
int red, blue, green, alpha;
for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) {

        dataElements = raster.getDataElements(x, y, dataElements);
        // extract colors
        red   = colorModel.getRed(dataElements);
        blue  = colorModel.getBlue(dataElements);
        green = colorModel.getGreen(dataElements);
        alpha = colorModel.getAlpha(dataElements);
    }
}