Set red 2d array values using for loop

后端 未结 3 447
别那么骄傲
别那么骄傲 2021-01-27 19:13

I am trying to create a method that will get all of the red values in an image and display only the red values. I am having trouble with my getRedImage() method. I am new to thi

3条回答
  •  天命终不由人
    2021-01-27 19:24

    I finally figured it out:

    public SimpleRGB getRedImage()
    {
        SimpleRGB redImage = new SimpleRGB(width, height);
    
        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                redImage.setRed(i, j, getRed(i, j));
                redImage.setGreen(i, j, getGreen(i, j, 0);
                redImage.setBlue(i, j, getBlue(i, j, 0));
            }
        }
    
    return redImage;
    }
    

    I had the basic structure correct but I was altering THIS red/green/blue instead of adding redImage.setRed to modify the NEW object.

提交回复
热议问题