-2

I need to capture image from camera and store it to imageView.

Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePicture, 0);

And onActivityResult method:

Uri selectedImage = imageReturnedIntent.getData();
mPhoto.setImageURI(selectedImage);
xevilboss
  • 55
  • 2
  • 6

1 Answers1

2

just try like this:

This code for capture the image from camera and displayed in imageview.

public class MainActivity extends ActionBarActivity {
    ImageView imgFavorite;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        }
    public void imageClick(View view){
       imgFavorite =(ImageView)findViewById(R.id.imageView1);
        open();
    }
    public void open(){
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //IMAGE CAPTURE CODE
        startActivityForResult(intent, 0);
    }
     protected void onActivityResult(int requestCode,int resultCode,Intent data){
     super.onActivityResult(requestCode,resultCode,data);
        Bitmap bitmap=(Bitmap)data.getExtras().get("data");
        imgFavorite.setImageBitmap(bitmap);
     }
}

xml file:

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="14dp"
    android:layout_marginTop="16dp"
    android:contentDescription="@string/hello_world"
    android:onClick="imageClick"
    android:src="@drawable/camera_launcher" />
RaMeSh
  • 3,330
  • 2
  • 19
  • 31