2016-07-06 1 views
1

私はImageView(四角形)を持っていますが、画像を一定の方法で表示する必要があります。正方形の左側と右側(写真1)は、写真が横向きに撮影されている場合は、正方形の上下にスペースが必要です。それはどのように可能ですか?おそらく、そのための特別なScaleTypeが存在するでしょうか?特定の方法でImageViewに画像を表示するには

写真1:

enter image description here

写真2:私は、この例ではあなたを助けることを願って

enter image description here

+2

ImageView.ScaleType.CENTER_INSIDE:https://developer.android.com/reference/android/widget/ImageViewを。 ScaleType.html – yongsunCN

+0

@youngsunCN、それは風景画像と完全にうまく動作しますが、縦向きで撮影された画像は風景と同じように表示されます(ただし回転が間違っている)。何故ですか? –

+0

あなたは画像の例をアップロードしてください。 – yongsunCN

答えて

1

// OnActivityResult方法

    Uri selectedImage = data.getData(); 
        if (selectedImage == null) { 
         imagePath = data.getStringExtra(GOTOConstants.IntentExtras.IMAGE_PATH); 

         Bitmap my_bitmap_camera = BitmapFactory.decodeFile(imagePath); 

         ExifInterface exif = new ExifInterface(imagePath); 
         int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); 

         switch (orientation){ 
          case ExifInterface.ORIENTATION_ROTATE_90: 
           Matrix matrix = new Matrix(); 
           matrix.postRotate(90); 
           my_bitmap_camera = Bitmap.createBitmap(my_bitmap_camera, 0, 0, my_bitmap_camera.getWidth(), my_bitmap_camera.getHeight(), matrix, true); 
           break; 
         } 

         ivScreenshot1.setImageBitmap(my_bitmap_camera); 
        } 

// XML

  <RelativeLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 

       <ImageView 
        android:id="@+id/ivScreenshot1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"/> 

      </RelativeLayout> 

//また、あなたがこの記事をチェックすることができます。How to get the Correct orientation of the image selected from the Default Image gallery

関連する問題