我正在处理裁剪图像类,但遇到了回收的位图问题:
03-02 23:14:10.514: E/AndroidRuntime(16736): FATAL EXCEPTION: Thread-1470
03-02 23:14:10.514: E/AndroidRuntime(16736): java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@428e5450
03-02 23:14:10.514: E/AndroidRuntime(16736): at android.graphics.Canvas.throwIfRecycled(Canvas.java:1026)
03-02 23:14:10.514: E/AndroidRuntime(16736): at android.graphics.Canvas.drawBitmap(Canvas.java:1096)
03-02 23:14:10.514: E/AndroidRuntime(16736): at android.graphics.Bitmap.createBitmap(Bitmap.java:604)
03-02 23:14:10.514: E/AndroidRuntime(16736): at eu.janmuller.android.simplecropimage.CropImage$1.prepareBitmap(CropImage.java:630)
03-02 23:14:10.514: E/AndroidRuntime(16736): at eu.janmuller.android.simplecropimage.CropImage$1.run(CropImage.java:636)
03-02 23:14:10.514: E/AndroidRuntime(16736): at eu.janmuller.android.simplecropimage.CropImage$6.run(CropImage.java:343)
03-02 23:14:10.514: E/AndroidRuntime(16736): at eu.janmuller.android.simplecropimage.Util$BackgroundJob.run(Util.java:175)
03-02 23:14:10.514: E/AndroidRuntime(16736): at java.lang.Thread.run(Thread.java:856)
Run Code Online (Sandbox Code Playgroud)
出现错误的行是mScale = 256.0F / mBitmap.getWidth();(第630行),请搜索此行以获取更多信息.
注意,在添加checkRotation()函数之前,代码没有此错误.并且该函数返回一个位图,该位图导致了异常.这是提示
此外,在我复制原始位图并回收旧位图的函数中,所以它不应该是问题的根源,建议您不要逐个查看代码,而是搜索关键字.谢谢你的帮助.
/**
* The activity can crop specific region of interest …Run Code Online (Sandbox Code Playgroud)