2016-02-15 34 views
-1

我使用imageview從圖庫中顯示圖像。Android Imageview和Matrix

不確定,但我的圖像變得很少扭曲和傾斜。

我曾嘗試縮放類型FITXY,但它不保持長寬比。

原始圖像 enter image description here

我有什麼是目前 enter image description here

我想必須有類似

enter image description here

我使用下面的XML

<ImageView 
          android:id="@+id/imageview1" 
          android:layout_width="80dp" 
          android:layout_height="76dp" 
          android:src="@drawable/ic_add_a_photo_black_361px" 
          android:background="@drawable/back" 
          android:scaleType="matrix" 
          android:layout_marginRight="20dp" 
          android:layout_marginBottom="20dp" 
          /> 

及以下代碼。

Bitmap bMap = BitmapFactory.decodeFile(selectedImagePath); 
       imageView1.setImageBitmap(bMap); 
       Matrix mat = imageView1.getImageMatrix(); 

       RectF drawableRect = new RectF(0, 0, bMap.getWidth(), bMap.getHeight()); 
       RectF viewRect = new RectF(0, 0, imageView1.getWidth(), imageView1.getHeight()); 
       mat.setRectToRect(drawableRect, viewRect, Matrix.ScaleToFit.FILL); 
       //mat.postScale(0.1f, 0.1f); 
       imageView1.setImageMatrix(mat); 

任何幫助將非常感激。使用

+0

爲什麼要使用矩陣 – theLazyFinder

+0

我不知道......我想對圖像的小變焦鏡頭.. 。 – Manish

+0

'FIT_XY'的文檔:'FIT_XY使用FILL縮放圖像'和'FILL':'填充X和Y的縮放比例,以便src完全匹配dst。這可能會改變src.的長寬比。' – pskink

回答

0

嘗試android:adjustViewBounds="true"

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:adjustViewBounds="true" 
    /> 

看到this tutorial

+0

與矩陣或沒有? – Manish

+0

沒有任何縮放類型 –

+0

不工作.. :( – Manish