Converting an image captured by camera to grayscale

by Sharmila » Thu, 09 Jul 2009 06:22:41 GMT


Sponsored Links
 Hi guys,
I have a camera application that captures a 640x480 image.I want to
convert this image to grayscale.I know I have to use the setSaturatio
(float sat) in the ColorMatrix method to zero but I dnt know how I can
set it to grayscale...
Can someone please help me out?
Thanks.
--~--~---------~--~----~------------~-------~--~----~



Converting an image captured by camera to grayscale

by Jack Ha » Thu, 09 Jul 2009 07:39:23 GMT


 You can try something like the following:

    Bitmap grayscaleBitmap = Bitmap.createBitmap(
        colorBitmap.getWidth(), colorBitmap.getHeight(),
        Bitmap.Config.RGB_565);
    Canvas c = new Canvas(grayscaleBitmap);
    Paint p = new Paint();
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);
    ColorMatrixColorFilter cmcf = new ColorMatrixColorFilter(cm);
    p.setColorFilter(cmcf);
    c.drawBitmap(colorBitmap, 0, 0, p);

--
Jack Ha
Open Source Development Center
obilestick together

The views, opinions and statements in this email are those of
the author solely in their individual capacity, and do not
necessarily represent those of T-Mobile USA, Inc.




--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. Working with the new ContactContracts API

Hi Jake,

The database structure is actually extremely straightforward:

"Contacts" represents an aggregated contact
"RawContacts" represents a contact as it was inserted by the sync adapter.
 RawContact has a CONTACT_ID field that binds it to a Contact.
"Data" represents everything about a RawContact: emails, phone numbers,
notes, birthday, high school graduation year, you name it.  Data has a
RAW_CONTACT_ID field that binds it a  RawContact.  The other important field
is MIMETYPE.  That's what determines the kind of data stored in a Data row.
 Everything else is just convenience API.

So here's the most common way of inserting a data row:

values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, Note.CONTENT_ITEM_TYPE);
values.put(Note.NOTE, "Blah blah blah");
resolver.insert(Data.CONTENT_URI, null, values);

I hope this helps.

- Dmitri








> > > 

2. How to check if the phone is in Standby from a service?

I am following standby mode by catching SCREEN_ON / SCREEN_OFF
broadcasts.
We've had a thread about this, here:

3. connect 2 emulators over lan

4. The account of the administrator

5. alarm being triggered, but app not launched...

6. alarm being triggered, but app not launched...

7. Not reading all of AudioRecord's output