createBitmap()使我成为一个java.lang.OutOfMemoryError [英] createBitmap() leads me into a java.lang.OutOfMemoryError

查看:1621
本文介绍了createBitmap()使我成为一个java.lang.OutOfMemoryError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着转动3 imageViews(或他们背后的位图更好)每10-100ms。
我做的旋转是这样的:

i try to rotate 3 imageViews (or better the Bitmaps behind them) every 10-100ms. i do the rotation like this:

ImageView ivLoad;
Bitmap bMapLoad;

....

Matrix mat=new Matrix();
mat.reset();
mat.postScale(1.55f, 1.55f);
mat.postRotate((float)currentLoadDegree+(float)LoadDegree);
bMapLoad = Bitmap.createBitmap(bMapLoadgr, 0, 0, bMapLoadgr.getWidth(), bMapLoadgr.getHeight(), mat, true);
ivLoad.setImageBitmap(bMapLoad);
ivLoad.setScaleType(ScaleType.CENTER);

....

我第一次开始全部的寄托都工作正常的应用程序。
第二次也适用
但第三次我启动它与下面的错误crashs应用程序:

the first time i start the app everthing works fine. second time also works but the 3rd time i start the app it crashs with the following error:

03-27 10:01:09.234: E/AndroidRuntime(3603): java.lang.OutOfMemoryError
03-27 10:01:09.234: E/AndroidRuntime(3603):     at android.graphics.Bitmap.nativeCreate(Native Method)    
03-27 10:01:09.234: E/AndroidRuntime(3603):     at android.graphics.Bitmap.createBitmap(Bitmap.java:605)  
03-27 10:01:09.234: E/AndroidRuntime(3603):     at android.graphics.Bitmap.createBitmap(Bitmap.java:551)

很长一段时间,我发现后,尝试当我调用System.exit(0)中的onDestroy梅索德全部的寄托工作。
现在我不知道是否会有更好的办法,因为在谷歌大量peaople的意思是System.exit(0)是不安全的。

after trying around a long time i found out that when i call System.exit(0) in the onDestroy methode everthing works. now i don't know if there would be a better way because on google a lot of peaople mean that System.exit(0) is unsafe.

所以我会得到这个问题的?

so will i get problems with this?

推荐答案

您不应该重新创建旋转的每一步位图,而不是你应该尝试绘制它旋转。这也是可能的矩阵(你已经使用),并避免过多的内存使用情况。

You shouldn't recreate the bitmap on every step of the rotation, instead you should just try to draw it rotated. That's also possible with a Matrix (what you already use) and will avoid the excessive memory usage.

<一个href=\"http://stackoverflow.com/questions/4166917/android-how-to-rotate-a-bitmap-on-a-center-point\">Android:如何在一个中心点旋转一个位图

这篇关于createBitmap()使我成为一个java.lang.OutOfMemoryError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆