可能重複:
OutOfMemoryError: bitmap size exceeds VM budget :- AndroidOutOfMemory例外時的處理的圖像
林書面其使用圖像從庫中的程序的過程,並然後將它們顯示在一個活動(一個圖像公關活動)。不過我已經碰到這個錯誤一遍又一遍三天直而不做消除它的任何進展:
07-25 11:43:36.197: ERROR/AndroidRuntime(346): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
我的代碼流程如下:
當用戶按下一個按鈕的意圖被激發通往畫廊:
Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
galleryIntent.setType("image/*");
startActivityForResult(galleryIntent, 0);
一旦用戶選擇的圖像是在imageview的呈現的圖像:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView
android:background="#ffffffff"
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:maxWidth="250dip"
android:maxHeight="250dip"
android:adjustViewBounds="true"/>
</LinearLayout>
在onActivityResult方法我有:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == RESULT_OK) {
switch(requestCode) {
case 0: // Gallery
String realPath = getRealPathFromURI(data.getData());
File imgFile = new File(realPath);
Bitmap myBitmap;
try {
myBitmap = decodeFile(imgFile);
Bitmap rotatedBitmap = resolveOrientation(myBitmap);
img.setImageBitmap(rotatedBitmap);
OPTIONS_TYPE = 1;
} catch (IOException e) { e.printStackTrace(); }
insertImageInDB(realPath);
break;
case 1: // Camera
的decodeFile方法是從here和resolveOrientation方法只是包裝位圖到矩陣,順時針旋轉90度使它轉動。
我真的很希望有人能幫我解決這件事。
重複http://stackoverflow.com/questions/2928002/outofmemoryerror-bitmap-size-exceeds-vm-budget-android或http://stackoverflow.com/questions/6131927/bitmap-size-exceeds-vm - 在Android預算? – THelper
@THelper:你知道如何解決這個問題嗎?根據您提供的兩個鏈接,我已經實施了'解決方案',但它沒有幫助 – Arcadia