0

i am getting a problem in fetching an image captured by camera into image view of another activity so please, find out the problem.....

      public void onClick(View v) {

                    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);  

                    startActivityForResult(cameraIntent, CAMERA_REQUEST);   

and the onActivityresult() is

protected void onActivityResult(int requestCode, int resultCode, Intent data,Uri mCapturedImageURI)
   {

       super.onActivityResult(requestCode, resultCode, data);
       if(requestCode==CAMERA_REQUEST&&resultCode==RESULT_OK)
         {
           String[] projection = { MediaStore.Images.Media.DATA}; 

           Cursor cursor = managedQuery(mCapturedImageURI, projection, null, null, null); 
           int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
           cursor.moveToFirst(); 
           String picturepath = cursor.getString(column_index_data);
           Log.d("TAG", "getLastImageId::path " + picturepath);
           Intent   camintent= new Intent(MainActivity.this,GalleryActivity.class);
             camintent.putExtra("imagePath",picturepath );
             startActivity(camintent);
 }
}

and my another(receiving) activity is........

      private void getData(){

        String ps=getIntent().getStringExtra("imagePath");
        img.setImageBitmap(BitmapFactory.decodeFile(ps));
     }
amanjain4all
  • 103
  • 1
  • 1
  • 5

2 Answers2

1
protected void onActivityResult(int requestCode, int resultCode, Intent data,Uri mCapturedImageURI)
   {

       super.onActivityResult(requestCode, resultCode, data);
       if(requestCode==CAMERA_REQUEST&&resultCode==RESULT_OK)
         {
           Bitmap bitmapImage = (Bitmap) intent.getExtras().get("data");
           Intent   camintent= new Intent(MainActivity.this,GalleryActivity.class);
           camintent.putExtra("bitmap", bitmapImage);
           startActivity(camintent);
 }
}

And retrieve the Bitmap Image in second Activity

private void getData(){

        Bitmap bitImage=getIntent().getParcelableExtra("bitmap");
        img.setImageBitmap(bitImage);

     }
Amit Gupta
  • 8,914
  • 1
  • 25
  • 33
0

Look here for an example on how to launch the camera and then retrieve the image: Capture Image from Camera and Display in Activity

protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {  
        Bitmap photo = (Bitmap) data.getExtras().get("data"); 
        imageView.setImageBitmap(photo);
    }  
} 

If you want to pass the results between two different activities after receiving the image from the camera, you could save the bitmap as a file and then read it in the second activity.

Community
  • 1
  • 1
Sophicles
  • 64
  • 8