2013-08-06 48 views
0
08-06 11:35:01.851: E/AndroidRuntime(10736): FATAL EXCEPTION: main 
08-06 11:35:01.851: E/AndroidRuntime(10736): java.lang.OutOfMemoryError 
08-06 11:35:01.851: E/AndroidRuntime(10736): at  android.graphics.BitmapFactory.nativeDecodeStream(Native Method) 
08-06 11:35:01.851: E/AndroidRuntime(10736): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:582) 
08-06 11:35:01.851: E/AndroidRuntime(10736): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:380) 
08-06 11:35:01.851: E/AndroidRuntime(10736): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:413) 
08-06 11:35:01.851: E/AndroidRuntime(10736): at com.accusol.realestate.property.Property3AddFragmentActivity.onClick(Property3AddFragmentActivity.java:812) 
08-06 11:35:01.851: E/AndroidRuntime(10736): at android.view.View.performClick(View.java:3558) 
08-06 11:35:01.851: E/AndroidRuntime(10736): at android.view.View$PerformClick.run(View.java:14157) 
08-06 11:35:01.851: E/AndroidRuntime(10736): at android.os.Handler.handleCallback(Handler.java:605) 
08-06 11:35:01.851: E/AndroidRuntime(10736): at android.os.Handler.dispatchMessage(Handler.java:92) 
08-06 11:35:01.851: E/AndroidRuntime(10736): at android.os.Looper.loop(Looper.java:137) 
08-06 11:35:01.851: E/AndroidRuntime(10736): at android.app.ActivityThread.main(ActivityThread.java:4514) 
08-06 11:35:01.851: E/AndroidRuntime(10736): at java.lang.reflect.Method.invokeNative(Native Method) 
08-06 11:35:01.851: E/AndroidRuntime(10736): at java.lang.reflect.Method.invoke(Method.java:511) 
08-06 11:35:01.851: E/AndroidRuntime(10736): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) 
08-06 11:35:01.851: E/AndroidRuntime(10736): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) 
08-06 11:35:01.851: E/AndroidRuntime(10736): at dalvik.system.NativeStart.main(Native Method) 

我用下面的代碼來顯示圖像Android的顯示圖像

vi = inflator.inflate(R.layout.item_image, null); 

Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); 
ImageVIew imgeview=(ImageVIew)vi.findViewById(R.id.imgItem); 
imgeview.setImageBitmap(myBitmap); 
vi.setTag(i); 

這是在brimapFactory.decodFile crasing ......當有大的圖像文件

+0

你需要做一些功課:http://developer.android.com/training/displaying-bitmaps/manage-memory.html – gunar

回答

0

使用下面的代碼重新取樣您的圖像文件,然後將位圖設置爲imageview。

// decodes image and scales it to reduce memory consumption 
public static Bitmap decodeFile(File f) { 
    try { 
     // Decode image size 
     BitmapFactory.Options o = new BitmapFactory.Options(); 
     o.inJustDecodeBounds = true; 
     BitmapFactory.decodeStream(new FileInputStream(f), null, o); 

     // The new size we want to scale to 
     final int REQUIRED_SIZE = 70; 

     // Find the correct scale value. It should be the power of 2. 
     int scale = 1; 
     while (o.outWidth/scale/2 >= REQUIRED_SIZE && o.outHeight/scale/2 >= REQUIRED_SIZE) 
      scale *= 2; 

     // Decode with inSampleSize 
     BitmapFactory.Options o2 = new BitmapFactory.Options(); 
     o2.inSampleSize = scale; 
     return BitmapFactory.decodeStream(new FileInputStream(f), null, o2); 
    } catch (FileNotFoundException e) { 
    } 
    return null; 
} 
+0

它的工作,但它看起來太blury圖像 – CoronaPintu

+0

@Pintu Corna,取出通過改變最終的int REQUIRED_SIZE = 70來模糊圖像;值。即檢查它是否有不同的值 – mdDroid