title: Picking a photo from gallery and show in a image view
body: <p>I have an app, which has a button to select a photo from your gallery and it works fine and after selecting the image my app show came back to the activity and shows the image in an image View.</p>
  
  <p>Every is working fine but sometimes ,when i select some particular images the preview is not showing. I have also tried to compress the image still its not working</p>
  
  <p>My code is below..
  <strong>In <code>onCreate()</code></strong></p>
  
  <pre><code>galeryBtn=(Button)findViewById(R.id.buttonGallery);
  galeryBtn.setOnClickListener(new OnClickListener() {
  
      @Override
      public void onClick(View v) {
        Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        startActivityForResult(i, RESULT_LOAD_IMAGE);
  
      }
  });
  </code></pre>
  
  <p><strong>In onActivityResult(int requestCode, int resultCode, Intent data)</strong></p>
  
  <pre><code>if (requestCode == RESULT_LOAD_IMAGE &amp;&amp; resultCode == RESULT_OK &amp;&amp; null != data) {
      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]);
      String picturePath = cursor.getString(columnIndex);
      cursor.close();
      // String picturePath contains the path of selected Image
  
      // Show the Selected Image on ImageView
      ImageView imageView = (ImageView) findViewById(R.id.imgView);
      imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
  
  } 
  </code></pre>