小编Ahs*_*san的帖子

无法压缩回收的位图

我有一个回收bitmap的问题.我有所有null和代码回收.不确定我做错了什么.

我的代码:

ByteArrayOutputStream stream = new ByteArrayOutputStream();               
bmp = DecodeImage.decodeFile(imgpath, 450, 450, true);
bmp.compress(Bitmap.CompressFormat.JPEG, 100 , stream);     
Image img = Image.getInstance(stream.toByteArray()); 
Run Code Online (Sandbox Code Playgroud)

错误信息:

07-12 15:44:11.924: E/AndroidRuntime(415): FATAL EXCEPTION: Thread-9850
07-12 15:44:11.924: E/AndroidRuntime(415): java.lang.IllegalStateException: Can't compress 
a recycled bitmap
07-12 15:44:11.924: E/AndroidRuntime(415):  at 
android.graphics.Bitmap.checkRecycled(Bitmap.java:272)
07-12 15:44:11.924: E/AndroidRuntime(415):  at 
android.graphics.Bitmap.compress(Bitmap.java:896)
07-12 15:44:11.924: E/AndroidRuntime(415):  at com.multiprvt.PDF$1.run(PDF.java:329)
07-12 15:44:11.924: E/AndroidRuntime(415):  at java.lang.Thread.run(Thread.java:856)
Run Code Online (Sandbox Code Playgroud)

解码为位图降低分辨率的类.

    public class DecodeImage
       {

       //decodes image and scales it to reduce memory consumption
         public static Bitmap decodeFile(File bitmapFile, int requiredWidth, int 
    requiredHeight, …
Run Code Online (Sandbox Code Playgroud)

android bitmap

3
推荐指数
1
解决办法
5070
查看次数

标签 统计

android ×1

bitmap ×1