我正在使用Gallery-widget和很多位图.
为了擦除位图,我使用Bitmap.recycle().结果我在logcat上看到下一个消息:
08-18 17:49:26.020: INFO/dalvikvm-heap(13847): Grow heap (frag case) to 22.373MB for 2457616-byte allocation
08-18 17:49:26.060: DEBUG/dalvikvm(13847): GC_FOR_ALLOC freed 1K,36% free 22835K/35143K,paused 27ms
08-18 17:49:26.230: DEBUG/dalvikvm(13847): GC_CONCURRENT freed <1K,paused 2ms+3ms
08-18 17:49:28.070: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.080: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.110: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.120: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.140: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.160: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.180: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.190: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.210: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.230: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.240: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.260: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.280: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.290: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.310: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.330: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.350: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.360: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.380: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.400: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.410: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.430: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.450: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.500: INFO/System.out(13847): Image width: 144; height: 108
08-18 17:49:28.570: DEBUG/dalvikvm(13847): GC_FOR_ALLOC freed 4094K,42% free 20449K/35143K,paused 27ms
08-18 17:49:28.620: INFO/dalvikvm-heap(13847): Grow heap (frag case) to 22.385MB for 2457616-byte allocation
Gallery-widget上的项目是黑色的.
但应用程序工作.
你对这个问题有什么想法吗?
最佳答案
我刚遇到同样的问题.问题在于,通过调用recycle(),您可以销毁引用图像像素数据的本机对象,并将对象本身(位图)标记为“死”.如果没有其他对象引用这些数据,它们将被GC释放.所以有两件事可能发生在你身上:
原文链接:https://www.f2er.com/android/430485.html>位图只是由GC收集,因此渲染器没有数据可供使用.
>由于位图本身已标记为死,因此无法从/向其读取/写入像素
因此,如果您正在使用/引用此位图并将其回收,那么您只是拒绝为每个人访问它.至少我这样理解.仔细阅读:
http://developer.android.com/reference/android/graphics/Bitmap.html#recycle%28%29
因此,只有在确定没有人使用/引用位图对象时才应使用回收.我希望它有所帮助.