[android-developers] Re: Pls help required ! : setPreviewCallBack - Bitmap

2009-12-02 Thread Garfield
On 1.5 and 1.6, there is no way to know supported preview sizes so
apps should not call setPreviewSize. Apps should call getPreviewSize
to know the current preview size. On 2.0, Apps should call
getSupportedPreviewSizes before setPreviewSize.

It's the same for setPictureFormat. On 1.5 and 1.6, apps should only
call getPictureFormat. On 2.0 apps shoudl call
getSupportedPictureFormat before setPictureFormat. I think what you
want is setPreviewFormat, not setPictureFormat. G1 and MyTouch3G only
supports YCbCr_420_SP (NV21) preview format and jpeg picture format on
1.5 and 1.6.

PS:
http://developer.android.com/reference/android/hardware/Camera.Parameters.html#getSupportedPreviewSizes()
http://www.fourcc.org/yuv.php#NV21

On Dec 2, 1:22 am, Jarcikon jarci...@gmail.com wrote:
 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 yourhelp

  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_);

                  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


[android-developers] Re: Pls help required ! : setPreviewCallBack - Bitmap

2009-12-01 Thread Jarcikon
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 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_);

                 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


[android-developers] Re: Pls help required ! : setPreviewCallBack - Bitmap

2009-12-01 Thread Jarcikon
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_);

                 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