• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps grayscale question (again)

Hi all,

I have to ask this question again as I have tried the developer guide, stackoverflow, myriad of books etc and I m getting nowhere.

What I am needing is a method to get grayscale pixel data from an image or preview. I am not interested in saving the picture as a jpeg etc, just need the grayscale data.

I am aiming at API 10 (as this is the device available for testing).

On top of this, I am not having any luck getting the camera to work on the Eclipse emulator.

Please remember that I am very new at this, so what may be obvious to you is very unlikely to be obvious to me.
 
I'm new to android development but an old-hat at java development so you can take this with a grain of salt, but if your image is a android.graphics.bitmap than the getPixels function will return your image data. You will probably need to calculate grayscale yourself with something such as...

Code:
    int grayvalue = (
                          (pixmap[x+(y*w)] & 255) + // blue?
                          ((pixmap[x+(y*w)] >> 8) & 255) + // green?
                          ((pixmap[x+(y*w)] >> 16) & 255) // red?
                        ) / 3;
See: getPixels(...) function at http://developer.android.com/reference/android/graphics/Bitmap.html
 
  • Like
Reactions: irradiation
Upvote 0
The forum broke the link. Just copy/paste it to the URL field of your web browser. As for the pixmap, that is my own language. The pixmap would be defined as

int pixmap[] = new pixmap[width*height];

This is where you could populate the RGB data of your image for quick processing, such as converting to grayscale.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones