Home > OS >  Capturing and displaying the same image
Capturing and displaying the same image

Time:04-04

I am working on a semester project and it requires that I send images from an android device to server without storing the image. I want to make sure my cameta application is working properly. I want to check this using an ImageView that displays the captured image on the screen. How can I do it? I thought I could load from drawable but I cannot add files to drawable during runtime.

Thanks for any support

CodePudding user response:

You don't need to save it to the drawable. These are the two steps:

1.Convert the captured image to Bitmap 2.Set the bitmap image to an imageview

Ref: StackOverflow Answer

 private void takePicture(){ //you can call this every 5 seconds using a timer or whenever you want
  Intent cameraIntent = new  Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
  startActivityForResult(cameraIntent, CAMERA_REQUEST); 
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {  
        Bitmap picture = (Bitmap) data.getExtras().get("data");//this is your bitmap image and now you can do whatever you want with this 
        imageView.setImageBitmap(picture); //for example I put bmp in an ImageView
    }  
} 
  • Related