Thursday, 1 November 2012

Capture image using camera and display in image view

Capture image using camera and save to sd-card then display in ImageView
 
To get more updates about this blog click on Join This Site---->
    This is simple tutorial that will help you to understand how to capture image using camera in android.

       In this demo you will capture image using camera and then image will be saved on sd-card then it will display image from sd-card.

You will also get absolute path of captured image also.

       Then you can set that image to ImageView or where ever else you want to use. 

       To use camera and sd-card in your application you need to add following permission in AndroidManifest.xml   for camera
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera"/>

for sd-card
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

If you like this tutorial then like us on facebook ----->
Then use below code to capture image using camera.

It will create one file named gtumcacocc.png in sd-card DCIM folder.

Intent cIntent
= new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File dir = Environment                       .getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
File output = new File(dir,"gtumcacocc.png");
cIntent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(output));
String filePath= output.getAbsolutePath();
startActivityForResult(cameraIntent, TAKE_PHOTO);


where TAKE_PHOTO
private static final int TAKE_PHOTO = 1;  
Display captured image from sd-card in ImageView.
ImageView imageView = new ImageView(this);
// Create Bitmap from sd-card.
Bitmap bitmap = BitmapFactory.decodeFile(
filePath);
// set bitmap to imageview
imageView.setImageBitmap(bitmap);   

Related Links
  1. How to create and use (nine) 9 patch image in android. 
  2. How to create custom intermediate Progress bar in Android.
  3. How to get total number of line from TextView. 
  4. Download Free Android projects with Source code.
  5. List of IT company in Rajkot, Ahmedabad, Gujarat, India.

2 comments:

Post a Comment

Fill free to post your Queries and Suggesion...!

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Bluehost Review