2013-10-28 39 views
0

我已經存儲在繪製文件夾的圖像,其中它的大小爲1MB和分辨率992x9000 我的代碼:負荷的形象從繪製大型高效URI

ImageView jpgView = (ImageView) findViewById(R.id.surahShow); 
Uri path = Uri.parse("android.resource://com.android.ta/" + R.drawable.myimage); 
jpgView.setImageURI(path); 

應用程序運行,並強制關閉

這裏是我的logcat :

10-28 10:55:07.321: E/AndroidRuntime(596): FATAL EXCEPTION: main 
10-28 10:55:07.321: E/AndroidRuntime(596): java.lang.OutOfMemoryError: bitmap size exceeds VM budget 
10-28 10:55:07.321: E/AndroidRuntime(596): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) 
10-28 10:55:07.321: E/AndroidRuntime(596): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:450) 
10-28 10:55:07.321: E/AndroidRuntime(596): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:326) 
10-28 10:55:07.321: E/AndroidRuntime(596): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:349) 
10-28 10:55:07.321: E/AndroidRuntime(596): at com.android.juzamma.SingleListSurah.decodeSampleBitmapFromResource(SingleListSurah.java:290) 
10-28 10:55:07.321: E/AndroidRuntime(596): at com.android.juzamma.SingleListSurah.onCreate(SingleListSurah.java:199) 
10-28 10:55:07.321: E/AndroidRuntime(596): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
10-28 10:55:07.321: E/AndroidRuntime(596): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586) 
10-28 10:55:07.321: E/AndroidRuntime(596): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638) 
10-28 10:55:07.321: E/AndroidRuntime(596): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
10-28 10:55:07.321: E/AndroidRuntime(596): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928) 
10-28 10:55:07.321: E/AndroidRuntime(596): at android.os.Handler.dispatchMessage(Handler.java:99) 
10-28 10:55:07.321: E/AndroidRuntime(596): at android.os.Looper.loop(Looper.java:123) 
10-28 10:55:07.321: E/AndroidRuntime(596): at android.app.ActivityThread.main(ActivityThread.java:3647) 
10-28 10:55:07.321: E/AndroidRuntime(596): at java.lang.reflect.Method.invokeNative(Native Method) 
10-28 10:55:07.321: E/AndroidRuntime(596): at java.lang.reflect.Method.invoke(Method.java:507) 
10-28 10:55:07.321: E/AndroidRuntime(596): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
10-28 10:55:07.321: E/AndroidRuntime(596): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
10-28 10:55:07.321: E/AndroidRuntime(596): at dalvik.system.NativeStart.main(Native Method) 

然後我試圖改變我的代碼:

public static int calculateInSampleSize(
      BitmapFactory.Options options, int reqWidth, int reqHeight){ 

     final int height = options.outHeight; 
     final int width = options.outWidth; 
     int inSampleSize = 2; 

     if (height/2 < reqHeight || width/2 < reqWidth) { 
      final int heightRatio = Math.round((float) height/(float) reqHeight); 
      final int widthRatio = Math.round((float) width/(float) reqWidth); 
inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio; 
      } 
     return inSampleSize; 
    } 

    public static Bitmap decodeSampleBitmapFromResource(Resources res, int resId, 
      int reqWidth, int reqHeight) { 

     final BitmapFactory.Options options = new BitmapFactory.Options(); 
     options.inJustDecodeBounds = true; 
     BitmapFactory.decodeResource(res, resId, options); 
     options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); 
     options.inJustDecodeBounds = false; 
     return BitmapFactory.decodeResource(res, resId, options); 
     } 
jpgView.setImageBitmap(decodeSampleBitmapFromResource(getResources(), R.drawable.myimage, 100, 100)); 

但仍強制關閉

我得到解決Strange out of memory issue while loading an image to a Bitmap objecthere

但事情,我一直沒能調整他們與我使用

代碼我做它的代碼安卓2.3.1

有人可以幫

回答

1

你的答案是UNIVERSAL IMAGE LOADER ....玩得開心:) :)

+0

或使用AQuery!這是一個偉大的用戶界面操作庫! –

+0

Jlazar89:感謝您的幫助 我試圖在我的eclipse中導入你的項目,但爲什麼不實現? – noel

+0

Niraj Adhikari:我不熟悉數據庫,應用程序也沒有使用數據庫 – noel