title: Getting photo from camera and gallery
body: <p>Hi,</p>
  
  <p>I am creating a simple Android app which allows user to select photo from either photo gallery or take one using camera. After getting the selected photo, I will start another activity to do something with the photo. However I have some problem displaying the photo in another activity.</p>
  
  <p>Here is the first activity to get photo:</p>
  
  <pre><code>public class GetPhoto extends Activity implements OnClickListener {
  
      ImageButton ibPhotoLib;
      ImageButton ibCamera;
      final static int FROM_CAMERA = 0, FROM_PHOTOLIB = 1;
      public static Bitmap bmp;
  
      @Override
      public void onClick(View v) {
          switch(v.getId()){
          case R.id.ibCamera:
              Intent cameraIntent = new Intent(
                      android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
              startActivityForResult(cameraIntent, FROM_CAMERA);
              break;
          case R.id.ibPhotoLib:
              Intent photoPickerIntent = new Intent(Intent.ACTION_PICK,
                      android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);             
              startActivityForResult(photoPickerIntent, FROM_PHOTOLIB);
              break;      
          }       
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);      
          if (resultCode == RESULT_OK) {
              switch (requestCode) {
              case FROM_CAMERA:
                  Bundle extras = data.getExtras();
                  bmp = (Bitmap)extras.get("data");               
                  break;
              case FROM_PHOTOLIB:
                  Uri chosenImageUri = data.getData();            
                  try {
                      bmp = Media.getBitmap(this.getContentResolver(), chosenImageUri);
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
                  break;
              }    
              Intent intent = new Intent(GetPhoto.this, PhotoProcessing.class);
              startActivity(intent);
          }
      }
  }
  </code></pre>
  
  <p>Then I start another activity (<code>PhotoProcessing</code>) and in this activity I will display the photo first. Here comes the problem if I take a photo using camera, it displays in portrait mode which is what I want. However if I choose a photo from gallery, it always displays horizontally, which is really annoying. Does anyone know how to solve this problem?</p>
  
  <p>And also when I try to get the width and height of the image:</p>
  
  <pre><code>float imageWidth = GetPhoto.bmp.getWidth();
  float imageHeight = GetPhoto.bmp.getHeight();
  </code></pre>
  
  <ul>
  <li>if the photo is taken from camera, <code>imageWidth</code> = <code>153</code>, <code>imageHeight</code> = <code>204</code></li>
  <li>if the photo is chosen from gallery, <code>imageWidth</code> = <code>3264</code>, <code>imageHeight</code> = <code>2448</code></li>
  </ul>
  
  <p>for the same image.</p>
  
  <p>Can anyone explain why this is so different? I am very confused.</p>
  
  <p>Any solutions or suggestions will be appreciated. Thanks.</p>