处理大位图时出现问题

发布于 2024-11-30 19:15:03 字数 5043 浏览 0 评论 0原文

错误如下:

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)

由“图像太大,你太笨了”引起....哈哈..

当图像太大时,是否有办法避免这种情况? :(

The error is the following:

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)

Caused by 'too big image you dumb'.... lol..

Is there anyway to avoid this when the image is too big? :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

格子衫的從容 2024-12-07 19:15:03

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

相关BitmapFactory.decodeFile 函数记录为:

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

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

You must pass options to the decode function to reduce the size of the bitmap as it reads by adding a BitmapFactory.Options argument in your code. This is because the VM has limited memory space for your process.

The prototype for the relevant BitmapFactory.decodeFile function is documented as:

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

You will need to read the BitmapFactory.Options section of the documentation to set the values appropriate to your situation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文