user3166385
user3166385

Reputation: 1

first pixel address of bitmap object on android

On visual studio c# .net framework for windows, there is Bitmapdata.scan0 that get first pixel address of bitmap object. Is there a class or method on android that can do same? How to find first pixel address of bitmap object on android?

Upvotes: 0

Views: 475

Answers (2)

Melquiades
Melquiades

Reputation: 8598

Say your bitmap is:

Bitmap bitmap;

Provided it's initialized and holds data, you can get the first pixel with:

int color = bitmap.getPixel(0, 0);

Upvotes: 0

Martin Cazares
Martin Cazares

Reputation: 13705

The pixels in android Bitmaps are stored as an array.

All you have to do is:

Bitmap.getPixel(x, y);

That method will return the pixel stored in the position x, y, and the bitmap range is:

0 - with on X

and 0 - height on Y.

So you have to do a sweep through all the table to get each pixel as follows:

for(int i = 0; i < bmp.getHeight(); i++){
   for(int j = 0; j < bmp.getWidth(); j++){
         int pixel = bmp.getPixel(j, i);
   }
}

Hope this Helps.

Regards!

Upvotes: 1

Related Questions