在 Android 上处理多个位图
我正在构建一个基本上响应触摸事件的 Android 应用程序,当触摸事件发生时,我会检测要执行的操作并对其采取行动。这些动作由显示不同的位图组成,因此动作实际上是一个动画:
- OnTouchEvent -> draw Bitmaps on SurfaceView
通常 1 个动画由大约 20 - 30 个大小为 28kbyte 的图像组成。 由于我需要应用程序具有非常灵敏的响应能力,因此我无法在“每次触摸”的基础上分配和取消分配内存,因此我希望加载所有位图(应该约为 12 MB),
但是当我加载的图像达到约 0.5 MB 时:
E/AndroidRuntime(10553): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
E/AndroidRuntime(10553): at android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
一遍又一遍......有什么想法吗?是否可以在 Canvas 上绘制图像而不创建位图?我可以在不使用 BitmapFactory 的情况下将 JPG 文件转换为位图吗? (我在这里读到:BitmapFactory OOM 让我发疯主要问题是位图数据使用本机堆而不是 VM 堆)
非常感谢任何帮助:D
预先感谢,
泽
I'm building an android app that basically answer to touch events, when a touch event occurs I detect which action to perform and act upon it. The actions consists of display different bitmaps, so an action is, in fact, an animation:
- OnTouchEvent -> draw Bitmaps on SurfaceView
Normally 1 animation consist of around 20 - 30 images with size 28kbyte.
As I need the app to be very responsive, I cannot allocate and deallocate memory on "per touch" basis so I wanted to have all the Bitmaps loaded (which should be around 12 MByte)
However when I reach around 0.5 MBytes of images loaded:
E/AndroidRuntime(10553): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
E/AndroidRuntime(10553): at android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
Over and over again.... any ideas ? Is it possible to draw images on Canvas without creating Bitmaps ? Can I convert my JPG files in Bitmaps without using BitmapFactory ? ( I read here: BitmapFactory OOM driving me nuts that the main issue is that Bitmap data uses the Native Heap instead of the VM Heap)
Any help much appreciated :D
Thanks in advance,
Ze
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论