Actually figured it out in the end! :)
Bitmap bm = Bitmap.createBitmap(500, 500,
Bitmap.Config.RGB_565);
Canvas c = new Canvas(bm);
Paint paint = new Paint();
ColorMatrix cm = new ColorMatrix();
cm.setSaturation(0);
ColorMatrixColorFilter f = new ColorMatrixColorFilter
(cm);
paint.setColorFilter(f);
int xo = (w-500)/2;
int yo = (h-500)/2;
c.drawBitmap(bmp, -xo, -yo, paint);
bmp.recycle();
Cheers.
On May 20, 12:07 pm, moa <[email protected]> wrote:
> I would like to convert a Bitmap to a grayscale array of bytes (one
> byte per pixel). At the same time I want to just crop at section from
> the middle. Having looked though the various api's it is not clear to
> me what the best way would be.
>
> The best way I have found in se java is as below;
>
> BufferedImage image = new BufferedImage(cropWidth, cropHeight,
> BufferedImage.TYPE_BYTE_GRAY);
> Graphics g = image.getGraphics();
> g.drawImage(colorImage, cropOffsetX, cropOffsetY, null);
> g.dispose();
>
> Leaving me with a graysale image of the right section;
>
> What is the equivalent method with android api's. I am guessing it is
> along these lines....
>
> Bitmap bm = Bitmap.createBitmap(500, 500,
> Bitmap.Config.ALPHA_8); // ALPHA_8?
> Canvas c = new Canvas(bm);
> Paint paint = new Paint(); // should something be set
> here to get grayscale?
> c.drawBitmap(bm, 200, 200, paint);
> bm..getPixels(...); // I want byte/pixel not int/
> pixel ??
>
> However, I have two questions;
>
> 1) What is ALPHA_8? is that grayscale?
>
> I have a feeling that the grayscale effect should be done via some
> "saturation" on the paint object, right?
>
> 2) once I have the Bitmap in grayscale and the right size, what is the
> best way to get that to a byte[] of pixels (one byte per pixel) ?
>
> Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---