tags:

views:

2618

answers:

2

Hi,

I am trying to implement Camera application in android,and i got some code from net to create a Live Camera through WebCam.Upto this no problem.Now i have to capture the images when click the button, and i displayed the captured images in the Dialog window.Without any exception the program is running but the captured image is not displayed,some default image is displayed.

My code is

public void captureImage()
{
 Camera.Parameters params = camera.getParameters();
 camera.setParameters(params);
 Camera.PictureCallback jpgCallback = new PictureCallback() 
 {
  public void onPictureTaken(byte[] data, Camera camera) 
  {
   try
   {
    Dialog d=new Dialog(c);
       d.setContentView(0x7f030000);
    BitmapFactory.Options opts = new BitmapFactory.Options();
       Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length,opts);
       TextView tv=(TextView)d.findViewById(0x7f050001);
       ImageView i=(ImageView)d.findViewById(0x7f050000);
          i.setImageBitmap(bitmap);
       tv.setText("Hai"+data.length);
       d.show();
   }
   catch(Exception e)
   {
    AlertDialog.Builder alert=new AlertDialog.Builder(c);
    alert.setMessage("Exception1"+e.getMessage());
    alert.create();
    alert.show();
   }
  }

 };
 camera.takePicture(null, null, jpgCallback);
}

I have no idea from where this default image is coming,i don't how to slove this problem.Anyone knows about this please help me.Waiting for the Reply.....

+3  A: 

If this is on the emulator, the only available camera image is a default image.

On a completely unrelated note, DO NOT reference resources by raw numbers (e.g., d.setContentView(0x7f030000)). Use the generated R class (e.g., R.layout.something). Those numbers will change, and when they change your application will break.

CommonsWare
Is there any other way to capture the image displayed in the emulator Camera Application.
Rajapandian
I do not understand the question. The emulator's camera is an emulated camera. The Android Camera application, and any other application that uses Android's Camera object, will see an emulated "preview" and "picture" (e.g., ball on checkerboard background). If you want real pictures from a Camera, use a real device.
CommonsWare
A: 

whats the value "c" in this case?

Dialog d=new Dialog(c);

android