通过声明静态捕获位图并在Activity之间传递位图。
04-30 12:55:28.988: W/dalvikvm(4034): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
04-30 12:55:29.028: E/AndroidRuntime(4034): FATAL EXCEPTION: main
04-30 12:55:29.028: E/AndroidRuntime(4034): java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@40531360, 800x480
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.graphics.Canvas.throwIfRecycled(Canvas.java:973)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.graphics.Canvas.drawBitmap(Canvas.java:1062)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:332)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.widget.ImageView.onDraw(ImageView.java:943)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.view.View.draw(View.java:7014)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.view.ViewGroup.drawChild(ViewGroup.java:1732)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.view.View.draw(View.java:7126)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.view.ViewGroup.drawChild(ViewGroup.java:1732)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.view.ViewGroup.drawChild(ViewGroup.java:1730)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.view.ViewGroup.drawChild(ViewGroup.java:1730)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.view.ViewGroup.drawChild(ViewGroup.java:1730)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.view.ViewGroup.drawChild(ViewGroup.java:1730)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.view.View.draw(View.java:7017)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.widget.FrameLayout.draw(FrameLayout.java:357)
04-30 12:55:29.028: E/AndroidRuntime(4034): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2054)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.view.ViewRoot.draw(ViewRoot.java:1632)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.view.ViewRoot.performTraversals(ViewRoot.java:1335)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.view.ViewRoot.handleMessage(ViewRoot.java:1991)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.os.Handler.dispatchMessage(Handler.java:99)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.os.Looper.loop(Looper.java:150)
04-30 12:55:29.028: E/AndroidRuntime(4034): at android.app.ActivityThread.main(ActivityThread.java:4385)
04-30 12:55:29.028: E/AndroidRuntime(4034): at java.lang.reflect.Method.invokeNative(Native Method)
04-30 12:55:29.028: E/AndroidRuntime(4034): at java.lang.reflect.Method.invoke(Method.java:507)
04-30 12:55:29.028: E/AndroidRuntime(4034): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
04-30 12:55:29.028: E/AndroidRuntime(4034): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
04-30 12:55:29.028: E/AndroidRuntime(4034): at dalvik.system.NativeStart.main(Native Method)
非常感谢你!
答案 0 :(得分:0)
不要使用静态变量传递它,此规则适用于一般活动之间共享数据(不是最终的)。
相反,在意图包中传递它:
intent.putExtra("a bitmap", myBitmap);
如果这是一个大图像,您可能希望将其存储到文件中并传递意图中的文件路径。
答案 1 :(得分:0)
错误 -
尝试使用循环位图
当您尝试访问回收的位图时,会发生此错误。因此,您可能正在使用bitmap.recycle();
,然后尝试使用相同的位图,这是不可能的,您不能再使用回收的Bitmap。最好从那里创建一个新的Bitmap,或者设法不回收Bitmap。