Set red 2d array values using for loop

后端 未结 3 444
别那么骄傲
别那么骄傲 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:46

    I did not understand very well your question, but, if you have 3 2D arrays, one for each RGB:

    int[][] red = new int[1000][1000];
    int[][] green = new int[1000][1000];
    int[][] blue = new int[1000][1000];
    

    and you only want the red color in the image, just set to zero all other colors:

    public class SimpleRGB
    {
        private int width;
        private int height;
        private int[][] red = new int[1000][1000];
        private int[][] green = new int[1000][1000];
        private int[][] blue = new int[1000][1000];
    
        public SimpleRGB(int[][] red, int[][] green, int[][] blue) {
            this.red = red;
            this.green = green;
            this.blue = blue;
        }
    
        // some methods
    
        public int[][] getRed() {
            return red;
        }
    
        public int[][] getGreen() {
            return green;
        }
    
        public int[][] getBlue() {
            return blue;
        }
    
        // the method that interests you
    
        public SimpleRGB getRedImage() {
            return new SimpleRGB(red, new int[1000][1000], new int[1000][1000]);
        }
    }
    

    Creating a new array, all its elements are initialized by default to 0.

提交回复
热议问题