ImageView崩溃了应用程序

时间:2017-01-03 05:23:50

标签: android bitmap imageview android-bitmap

单击imageView时,我想以全屏显示图像。这是第一次有效,但之后就崩溃了。错误指向

startActivity(intent);

代码

Intent intent = new Intent(AddExpenses.this,FullScreenImage.class);
imageView.buildDrawingCache();
Bitmap image= imageView.getDrawingCache();
Bundle extras = new Bundle();
extras.putParcelable("imagebitmap", image);
intent.putExtras(extras);
startActivity(intent);
image.recycle();

FullScreenImage

public class FullScreenImage extends Activity {

    @SuppressLint("NewApi")

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.layout_full);
        Bundle extras = getIntent().getExtras();
        Bitmap bmp = (Bitmap) extras.getParcelable("imagebitmap");
        ImageView imgDisplay;
        Button btnClose;

        imgDisplay = (ImageView) findViewById(R.id.imgDisplay);
        btnClose = (Button) findViewById(R.id.btnClose);
        btnClose.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                FullScreenImage.this.finish();
            }
        });
        imgDisplay.setImageBitmap(bmp );
    }
}

logcat的

E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.IllegalStateException: Can't parcel a recycled bitmap
            at android.graphics.Bitmap.checkRecycled(Bitmap.java:256)
            at android.graphics.Bitmap.writeToParcel(Bitmap.java:1366)
            at android.os.Parcel.writeParcelable(Parcel.java:1254)
            at android.os.Parcel.writeValue(Parcel.java:1173)

我使用extras.putParcelable("imagebitmap",image.copy(image.getConfig(), true));但收到新错误

java.lang.IllegalStateException: Can't copy a recycled bitmap
            at android.graphics.Bitmap.checkRecycled(Bitmap.java:256)
            at android.graphics.Bitmap.copy(Bitmap.java:454)
            at com.example.tony.monthlyexpenses.AddExpenses$4.onClick(AddExpenses.java:176)

1 个答案:

答案 0 :(得分:0)

我认为这个问题是因为在意图被解雇后进行了诽谤。因此,只需将9 sgsgsgs 10 uwuwqmksam 的副本放在Intent上,而不是位图,就像这样:

Bitmap

检查这是否解决了这个问题。