2016-02-20 52 views
0

我有一個ImageView,大小爲70dp,寬度和高度。它用於我的ListView幷包含800x800的圖像src。更改ImageView的質量

我現在的問題是,這張圖片太大了,它看起來太在我的ImageView。 我該如何預防?

<ImageView 
    android:id="@+id/imageView_albumart" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_width="70dp" 
    android:layout_height="70dp" 
    android:layout_marginRight="5dp" 
    android:src="@drawable/cd_800x800" /> 

回答

1

其實你可以玩你的位圖。旋轉,壓縮,轉換其他格式等。 我們在下面的代碼中將質量從100降低到25。

因此,這是代碼:

Bitmap oldbitmap=Bitmap bitmap = ((BitmapDrawable)yourimageview.getDrawable()).getBitmap(); 
    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    oldbitmap.compress(Bitmap.CompressFormat.JPEG, 25,baos); 
    Bitmap newbitmap=BitmapFactory.decodeStream(new ByteArrayInputStream(baos.toByteArray())); 
    yourimageview.setImageBitmap(newbitmap); 
+0

這確實didnt幫助過我的ImageView還是很犀利。 Yerim seni –

+1

Bitmap scaled = Bitmap.createScaledBitmap(yourBitmap,300,300,true);這是分辨率下降到300x300 bizdeçaretükenmez.. –

+0

謝謝你的幫助,但我想我必須模糊的圖片有點因爲它仍然非常尖銳莫名其妙。 Eyvallah kardesim steamin varsa beni adlersen sevinirim:http://steamcommunity.com/profiles/76561198227006600 –