Arnouf,

After reading a little more, I realized what may be causing your
original problem, if you still intend to do it that way.  The
setPreviewSize method does not seem to work, at least on the G1 and
MyTouch3G.  So in your decodeYUV function you are assuming the data
returned will be 50*50 pixels.  I would check the data variable in
onPreviewFrame and I think you will find it is not 50 x 50.  You can
also do a getPreviewSize after setting the preview size and see what
it returns.

Mike

On Nov 18, 5:03 am, arnouf <arnaud.far...@gmail.com> 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to