Creating a 2D RGB Pixel Array from Bitmap

0

I can't seem to find any other code that uses a 2D instead of 1 - I just want to have each RGB value from 0-255 saved into an array the same size as the bitmap. The bitmap in my code is called newbitmap. The issue is when I try to put the RGB colors back together and put them into an array.

                int w = newbitmap.getWidth();
                int h = newbitmap.getHeight();
                //define the array size
                pixels = new int[w][h];


                for (int y = 0; y < h; y++){
                    for (int x = 0; x < w; x++){
                       int color = newbitmap.getPixel(x,y);
                        int  red = (color & 0x00ff0000) >> 16;
                        int  green = (color & 0x0000ff00) >> 8;
                       int  blue = color & 0x000000ff;
                        int alpha = (color>>24) & 0xff;
                        Color color1 = new Color(red,green,blue,alpha);
                        pixels[x][y] = color1;

                    }
                }
java
arrays
android-studio
image-processing
bitmap
asked on Stack Overflow Feb 8, 2018 by Garrett Soler

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0