How to capture image using camera in android

Here is the example for how to capture image using camera in android, this example is for the beginner and if you want to use camera for taking image then this tutorial will help you to capture image and show in imageview. 

Another thing is, Using this code snippet you can show your image captured from camera to the imageview. 

Here is the example:-
 
public static final int CAMERA_RESULT_CODE=1;

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
startActivityForResult(cameraIntent, CAMERA_RESULT_CODE); 

Put above code to your button action where you want to open camera action.
 
@Override 
protected void onActivityResult(int request_code, int result_code, Intent data) { 
    super.onActivityResult(request_code, result_code, data); 
	
    if (RESULT_OK == result_code) { 
        // Get Extra from the intent 
        Bundle extras = data.getExtras(); 
        // Get the returned image from extra 
        Bitmap bitmap = (Bitmap) extras.get("data"); 

        youimageview = (ImageView) findViewById(R.id.youimageview); 
        youimageview.setImageBitmap(bitmap); 
    } 
} 

Put Above content in your Activity. Using Only these lines of code you can capture image using camera in your android application. 

Happy Coding! 
Thanks.

Comments