我有一個8 mp的圖像,但它不能顯示在ImageView上,因爲它太大的文件。如何用一個BitmapFactory重新調整大小,然後將這個新圖像作爲ImageView的源代碼傳遞給XML?需要爲imageview調整圖像
我的XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/select"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select" />
<Button
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Info" />
</LinearLayout>
<ImageView
android:id="@+id/test_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
我的活動:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ImageView view;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize=8; //also tried 32, 64, 16
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher, options);
Drawable d = new BitmapDrawable(bmp);
view = (ImageView) findViewById(R.id.test_image_view);
view.setImageDrawable(d);
setContentView(R.layout.main);
}
它仍然崩潰,我張貼我的代碼,你可以快速瀏覽它嗎? – Aneem
@Aneem當然,它張貼到你的問題 –
@Aneem首先是 - 你不'decodeResource'方法設置好的你的選擇(這應該是最後的參數)。其次 - 也許值'16'是不是你正在尋找(你也可以嘗試32,64等) –