解决此问题的方法有三种。
1)首先将图像转换为字节数组,然后将其传递给Intent,在下一个活动中从Bundle中获取字节数组并将其转换为图像(Bitmap),再将其设置到ImageView中。
将Bitmap转换为字节数组:
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)
ByteArrayOutputStream stream = new ByteArrayOutputStream()
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream)
byte[] byteArray = stream.toByteArray()
将字节数组传入Intent:
Intent intent = new Intent(this, NextActivity.class);
intent.putExtra("picture", byteArray);
startActivity(intent);
从Bundle中获取字节数组并将其转换为位图图像:
Bundle extras = getIntent().getExtras();
byte[] byteArray = extras.getByteArray("picture");
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageBitmap(bmp);
2) 首先将图片保存到SD卡中,然后在下一个活动中将该图片设置为ImageView。
3) 将Bitmap传递到Intent中,并在下一个活动中从Bundle中获取bitmap,但问题是如果您的Bitmap / Image大小很大,则该图像在下一个活动中无法加载。