我使用imageview從圖庫中顯示圖像。Android Imageview和Matrix
不確定,但我的圖像變得很少扭曲和傾斜。
我曾嘗試縮放類型FITXY,但它不保持長寬比。
我想必須有類似
我使用下面的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);
任何幫助將非常感激。使用
爲什麼要使用矩陣 – theLazyFinder
我不知道......我想對圖像的小變焦鏡頭.. 。 – Manish
'FIT_XY'的文檔:'FIT_XY使用FILL縮放圖像'和'FILL':'填充X和Y的縮放比例,以便src完全匹配dst。這可能會改變src.的長寬比。' – pskink