views:

1935

answers:

1

Hello.

I'm writing an application for Android. I need to make some image processing on the picture taken from camera. I use Camera.PictureCallback to get the photo, and I get picture in byte array. The problem is I want to make operations on every pixel of photo (some filtering and other stuff) so I guess, have photo in byte array is not a bad idea. But I don't know how interpret information in this byte array... The only way I know to make the processing is use BitmapFactory.decodeByteArray() and then use Bitmap object. Is this a good way to handle a lot of image processing? Right now I use something look like this:

Bitmap mPhotoPicture mPhotoPicture = BitmapFactory.decodeByteArray(imageData, 0 , imageData.length);

mPhotoPicture = mPhotoPicture.copy(Bitmap.Config.RGB_565, true);

I appreciate any help.

+4  A: 

I'm not sure if decoding into a byte array is the best way to do it on Android, but I can offer what I know about image processing in general.

If you're using RGB_565, that means each pixel is 16 bits, or two of those bytes. The first 5 bits are red, the next 6 are green, and the last 5 are blue. Dealing with that is hairy in Java. I suggest you work with an easier format like ARGB_8888, which will mean you have 32 bits, or four bytes per pixel, and each byte is its own value (alpha, red, green, blue).

To test, try setting every fourth byte, like [3], [7], [11], etc., to 0. That should take out all of a particular channel, in this case, all the blue.

[2], [6], [10], etc. would be all the green values for each pixel.

(Note, the four components might go in the opposite order because I'm not sure about endianness! So I might have just told you how to take out the alpha, not the blue…)

Kevin Conner
Thanks for this useful information. Now I know from documentations that I can take picture photo only in these formats: PixelFormat.YCbCr_420_SP (NV21), PixelFormat.RGB_565, or PixelFormat.JPEGSo I guess, I try to write RGB_565 encoding.
Kubeczek
Right. Either edit in that format, or find a way to convert before you edit.
Kevin Conner