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)

我用下面的代码来显示图像

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 中出现的问题...当有大图像文件时

4

1 回答 1

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;
}
于 2013-08-06T06:15:31.193 回答