美文网首页Android常见bug
Android开发中使用 Bitmap.createBitmap

Android开发中使用 Bitmap.createBitmap

作者: ToBeTheOnlyOne | 来源:发表于2018-01-05 21:49 被阅读0次

    最近在开发一个应用的时候,使用了BitmapcreateBitmap()函数,在模拟器上运行的很好,可是到了真机上就出现了如下错误:

    AndroidRuntime: FATAL EXCEPTION: main
                                                                                     Process: tobetheonlyone.wifip2papplication, PID: 1873
                                                                                     java.lang.OutOfMemoryError
                                                                                         at android.graphics.Bitmap.nativeCreate(Native Method)
                                                                                         at android.graphics.Bitmap.createBitmap(Bitmap.java:822)
                                                                                         at android.graphics.Bitmap.createBitmap(Bitmap.java:799)
                                                                                         at android.graphics.Bitmap.createBitmap(Bitmap.java:766)
    

    刚开始很懵,不知道怎么回事,然后就上网查,想知道什么情况下可以导致OutOfMemory错误,找了好久,终于在一个外国的网站上找了一个或许可以的解决办法,就是在AndroidManifestapplication节点上加上

    android:largeHeap="true"
    

    这句就可以了,意思就是让设备给分配大的堆栈来处理Bitmap,这样就不会出现OutOfMemoryError这种错误了。
    这就是我的解决方案,希望可以帮到你~
    ps:自己开发了一个制作二维码的小应用,有兴趣的可以试一试~ _

    相关文章

      网友评论

        本文标题:Android开发中使用 Bitmap.createBitmap

        本文链接:https://www.haomeiwen.com/subject/ncqenxtx.html