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.....
ACTION_IMAGE_CAPTURE or MediaStore. ACTION_VIDEO_CAPTURE can be used to capture images or videos without directly using the Camera object.
This is done as follows: Intent camera_intent = new Intent(MediaStore. ACTION_IMAGE_CAPTURE); startActivityForResult(camera_intent, pic_id); Now use the onActivityResult() method to get the result, here is the captured image.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With