Arnouf,
I can't help you with that exact problem, but I have an app that does
something very similar (What Color). If you look a little deeper into
the decodeYUV function, you will see that it is returning ARGB values
in an array. Therefore, you do not really need to convert the image
to a Bitmap in order to analyze the colors present in the preview.
You can simply iterate through this array (pixels) and you will have
all the colors present with something like:
for(int i=i;i < pixels.length;i++){
int red = Color.red(pixels[i]);
int green = Color.green(pixels[i]);
int blue = Color.blue(pixels[i]);
}
Hope that helps.
Mike
On Nov 18, 5:03 am, arnouf <[email protected]> wrote:
> hi all,
>
> How can I convert the camera preview to a bitmap without use
> Takepicture ? The goal is to analyze the colors present inside the
> current preview.
>
> When I try to create bitmap (50x50 pixels of the current view) the
> result view is green with black lines. Apparently the preview uses the
> YUV color and I have to translate it in RGB to create my bitmap. I'm
> using a method found decodeYUV on this
> group:http://groups.google.fr/group/android-developers/browse_thread/thread...
>
> Below my code and thanks by advance for your help
>
> public void surfaceChanged(SurfaceHolder holder, int format, int
> width,
> int height) {
> Camera.Parameters parameters = mCamera.getParameters();
> parameters.setPictureFormat(PixelFormat.YCbCr_422_SP);
> parameters.setPreviewSize(50, 50);
> mCamera.setParameters(parameters);
> mCamera.startPreview();
>
> }
>
> Camera.PreviewCallback mPreviewCallback = new Camera.PreviewCallback()
> {
> public void onPreviewFrame(byte[] data, Camera camera) {
> int[] pixels = new int[50 * 50];
> decodeYUV(pixels, data, 50, 50);
> Bitmap bfInit = Bitmap.createBitmap(pixels, 50, 50,
> Bitmap.Config.ARGB_8888);
>
> if (bfInit != null) {
> imgfinal.setImageBitmap(bfInit);
>
> }}
>
>
--
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