Skip to content

Instantly share code, notes, and snippets.

@pacificregmi
Created December 18, 2015 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pacificregmi/be695c99c1a29e7c3f62 to your computer and use it in GitHub Desktop.
Save pacificregmi/be695c99c1a29e7c3f62 to your computer and use it in GitHub Desktop.
How to Capture Image from Android Camera and Display it Programmatically - CamereCaptureAndDisplayImage.java
//How to Capture Image from Camera and Display in Android ImageView/ Activity
package com.viralandroid.androidtutorial;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class CamereCaptureAndDisplayImage extends AppCompatActivity {
private static final int CAMERA_REQUEST = 1888;
ImageView mimageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.capture_image_from_camera_and_display);
mimageView = (ImageView) this.findViewById(R.id.image_from_camera);
Button button = (Button) this.findViewById(R.id.take_image_from_camera);
}
public void takeImageFromCamera(View view) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmap mphoto = (Bitmap) data.getExtras().get("data");
mimageView.setImageBitmap(mphoto);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment