-1

i am new in android i dont know how to set imageview in image from galary and camera. please help me.. when i capure image from camera that image not set at imageview see below code

 private static final int CAMERA_REQUEST = 1888;
 ImageView imageView;
 public void onCreate(Bundle savedInstanceState) {

     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_camera_capture);

     imageView = (ImageView) this.findViewById(R.id.imageView1);
     Button photoButton = (Button) this.findViewById(R.id.btncapture);

     photoButton.setOnClickListener(new View.OnClickListener() {

     @Override
     public void onClick(View v) {
          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) {
   Bitmap photo = (Bitmap) data.getExtras().get("data");
   imageView.setImageBitmap(photo);
  }

 }
Ravi Vaghela
  • 3,316
  • 2
  • 19
  • 44

1 Answers1

0

You will get the Uri of the file in onActivityResult() you need to find find the path f from the ContentResolver and then create Bitmap. For example-

            Uri selectedImage = data.getData();
            String[] filePathColumn = {MediaStore.Images.Media.DATA};
            Cursor cursor = getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            picturePath = cursor.getString(columnIndex);
            profileImage.setImageBitmap(BitmapFactory.decodeFile(picturePath));
            cursor.close();
Sanjeet A
  • 4,813
  • 3
  • 19
  • 37