0
点赞
收藏
分享

微信扫一扫

在两个Activity之间如何传递一张图片

秀妮_5519 2023-03-10 阅读 28


Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_target);     
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] b = baos.toByteArray();

Intent intent = new Intent(this, ActivityB.class);
intent.putExtra("picture", b);
startActivity(intent);

Bundle extras = getIntent().getExtras();
byte[] b = extras.getByteArray("picture");

Bitmap bmp = BitmapFactory.decodeByteArray(b, 0, b.length);
ImageView image = (ImageView) findViewById(R.id.imageView1);

image.setImageBitmap(bmp);


举报

相关推荐

0 条评论