简体   繁体   English

将视图转换为位图 (OutOfMemoryException)

[英]Convert View to Bitmap (OutOfMemoryException)

I have a Bitmap created from a View with the kotlin extesion drawToBitmamp() .我有一个从带有 kotlin 扩展drawToBitmamp()的视图创建的位图。 It works fine in most cases, but in low end devices, it throws an OutOfMemoryException.它在大多数情况下工作正常,但在低端设备中,它会抛出 OutOfMemoryException。

I've been doing research about how to handle Bitmaps efficiently, but I found nothing when it comes to bitmaps generated from View's.我一直在研究如何有效地处理位图,但是当涉及到从 View 生成的位图时,我一无所获。 Does anyone know how to avoid that exception while handling it better?有谁知道如何在更好地处理异常的同时避免该异常?

Any suggestion is welcome.欢迎任何建议。

Try this way to add试试这种方式添加

android:largeHeap="true" in application tag in manifest android:largeHeap="true" 在清单中的应用程序标签中

and also add below line并添加以下行

dexOptions{ javaMaxHeapSize "4g" } dexOptions{ javaMaxHeapSize "4g" }

in app level gradle or jvmargs=-Xmx2048M在应用程序级别 gradle 或 jvmargs=-Xmx2048M

Hope it may help you希望它可以帮助你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM