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
2 comments:
Great demo dude..
Really help your demo but I am getting problem in my Htc one device any solution.
Thanks for great information you write it very clean.
Android Application Development
Post a Comment
Fill free to post your Queries and Suggesion...!