处理大位图的问题

时间:2011-08-23 18:07:44

标签: android bitmap

错误如下:

08-24 15:03:59.998: ERROR/AlarmManager(2130): set: Alarm{47792078 type 1 android} package:android
08-24 15:04:00.455: ERROR/dalvikvm-heap(13274): 12582912-byte external allocation too large for this process.
08-24 15:04:00.455: ERROR/GraphicsJNI(13274): VM won't let us allocate 12582912 bytes
08-24 15:04:06.678: WARN/ActivityManager(2130): Launch timeout has expired, giving up wake lock!
08-24 15:04:06.697: WARN/ActivityManager(2130): Activity idle timeout for  HistoryRecord{47854538 com.ibssistemas.ibs/.gallery}
08-24 15:04:57.322: WARN/dalvikvm(13274): threadid=1: thread exiting with uncaught exception (group=0x3d5737d0)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274): FATAL EXCEPTION: main
08-24 15:04:57.365: ERROR/AndroidRuntime(13274): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at  android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:459)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:271)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at com.ibssistemas.ibs.gallery.openImage(gallery.java:69)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at com.ibssistemas.ibs.gallery$ImageAdapter.getView(gallery.java:91)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:192)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.view.View.measure(View.java:8171)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at  android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:696)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:306)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.view.View.measure(View.java:8171)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at  android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.view.View.measure(View.java:8171)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at  android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.view.View.measure(View.java:8171)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:526)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at  android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.view.View.measure(View.java:8171)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.view.View.measure(View.java:8171)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.os.Looper.loop(Looper.java:123)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at java.lang.reflect.Method.invokeNative(Native Method)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at java.lang.reflect.Method.invoke(Method.java:521)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-24 15:04:57.365: ERROR/AndroidRuntime(13274):     at dalvik.system.NativeStart.main(Native Method)

由于'太大的形象,你愚蠢'....大声笑..

当图像太大时,有没有避免这种情况? :(

1 个答案:

答案 0 :(得分:0)

您必须将选项传递给decode函数,以便在读取时通过在代码中添加BitmapFactory.Options参数来减小位图的大小。这是因为VM的进程存储空间有限。

相关BitmapFactory.decodeFile函数的原型记录为:

BitmapFactory.decodeFile(String pathName, BitmapFactory.Options opts)

您需要阅读文档的BitmapFactory.Options部分,以设置适合您情况的值。