我有一个问题是,1MB的jpg图像会变成12 MB的位图吗?我只是做一个在ImageView(全屏)中加载1MB的大图像的屏幕spalsh,我收到了这个错误:
Grow heap (frag case) to 27.724MB for 12582928-byte allocation
08-14 21:31:13.302: I/dalvikvm(15434): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
08-14 21:31:13.302: I/dalvikvm(15434): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:594)
08-14 21:31:13.302: I/dalvikvm(15434): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:447)
08-14 21:31:13.312: I/dalvikvm(15434): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
08-14 21:31:13.312: I/dalvikvm(15434): at android.content.res.Resources.loadDrawable(Resources.java:1963)
08-14 21:31:13.312: I/dalvikvm(15434): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
08-14 21:31:13.312: I/dalvikvm(15434): at android.widget.ImageView.<init>(ImageView.java:120)
08-14 21:31:13.312: I/dalvikvm(15434): at android.widget.ImageView.<init>(ImageView.java:110)
08-14 21:31:13.312: I/dalvikvm(15434): at java.lang.reflect.Constructor.constructNative(Native Method)
08-14 21:31:13.312: I/dalvikvm(15434): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
08-14 21:31:13.322: I/dalvikvm(15434): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
08-14 21:31:13.322: I/dalvikvm(15434): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-14 21:31:13.322: I/dalvikvm(15434): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
08-14 21:31:13.322: I/dalvikvm(15434): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
08-14 21:31:13.322: I/dalvikvm(15434): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
08-14 21:31:13.322: I/dalvikvm(15434): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
08-14 21:31:13.322: I/dalvikvm(15434): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
08-14 21:31:13.322: I/dalvikvm(15434): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
08-14 21:31:13.322: I/dalvikvm(15434): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:316)
08-14 21:31:13.322: I/dalvikvm(15434): at android.app.Activity.setContentView(Activity.java:1901)
答案 0 :(得分:0)
JPEG是压缩图像,但要在屏幕上显示,必须将其作为位图加载,并将每个像素转换为颜色值,因此每种颜色为8位,alpha为1,每个像素为4个字节。
因此JPEG的大小无关紧要,重要的是图像的宽度和高度。
编辑:
要在内存中使用较小的位图,请参阅此link以将位图缩小到屏幕上占用的大小。
ImageView和其他视图不会将位图缩放到大小,位图是原始的。但是你可以使用上面的链接缩小位图并保持内存使用率低。