SoFunction
Updated on 2025-04-09

Android programming method to obtain image pixel data based on BitMap

This article describes the Android programming method to obtain image pixel data based on BitMap. Share it for your reference, as follows:

The references seen online are:

int[] pixels = new int[()*()];//Save all pixel arrays, picture width × height(pixels,0,(),0,0,(),());
for(int i = 0; i < ; i++){
   int clr = pixels[i];
    int red  = (clr & 0x00ff0000) >> 16; //Take two higher    int green = (clr & 0x0000ff00) >> 8; //Two digits are selected    int blue = clr & 0x000000ff; //Pick two lower digits    ("r="+red+",g="+green+",b="+blue);
}

The third parameter in getPixels should be the width of the image

There is actually a better function

Bitmap bm = "Get bitmap picture";
(x,y);

Directly obtain the pixel point data at the x and y coordinates.

I hope this article will be helpful to everyone's Android programming design.