如何将 Bitmap 对象从一个活动传递到另一个活动

如何将 Bitmap 对象从一个活动传递到另一个活动

问题描述:

在我的活动中,我创建了一个 Bitmap 对象,然后我需要启动另一个 Activity,如何从子活动(将要启动的活动)传递这个 Bitmap 对象?

In my activity, I create a Bitmap object and then I need to launch another Activity, How can I pass this Bitmap object from the sub-activity (the one which is going to be launched)?

Bitmap 实现了 Parcelable,所以你总是可以带着意图传递它:

Bitmap implements Parcelable, so you could always pass it with the intent:

Intent intent = new Intent(this, NewActivity.class);
intent.putExtra("BitmapImage", bitmap);

并在另一端检索它:

Intent intent = getIntent(); 
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");