如何把图像中的包,并把它传递给另一个活动 [英] how to put image in a bundle and pass it to another activity

查看:79
本文介绍了如何把图像中的包,并把它传递给另一个活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有把图像中的包,并把它传递到另一个活动的一种方式?我做我的研究,并与putParcelable来到了,但我不知道如何从其他活动,以及如何将图像设置为一个ImageView的获得通过图像。我很卡,请帮助。

 如果别人(img4.getId()== v.getId()){
       意图的猜测=新意图(这一点,guess.class);
       束束=新包();
       位图图片4 = BitmapFactory.de codeResource(getResources(),R.drawable.renz);
       bundle.putParcelable(形象,图片4);
       guess.putExtras(包);
       startActivity(猜测);
   }


解决方案

所以,你可以像这样做,但与Parcelables并限制是活动之间的有效载荷有小于1MB总。它通常是更好的位图保存到一个文件并通过URI到图像到下一个活动。

 保护无效的onCreate(捆绑savedInstanceState){
    的setContentView(R.layout.my_layout);
    位图位图= getIntent()getParcelableExtra(图像)。
    ImageView的ImageView的=(ImageView的)findViewById(R.id.imageview);
    imageView.setImageBitmap(位图);
 }

is there a way to put an image in a bundle and pass it to another activity? i've done my research and came up with putParcelable but i don't know how to get the passed image from the other activity and how to set the image to an imageView. i'm stuck please help.

   else if(img4.getId() == v.getId()){
       Intent guess = new Intent(this, guess.class);
       Bundle bundle = new Bundle();       
       Bitmap image4 = BitmapFactory.decodeResource(getResources(), R.drawable.renz);
       bundle.putParcelable("image", image4);
       guess.putExtras(bundle);
       startActivity(guess);
   }

解决方案

So you can do it like this, but the limitation with the Parcelables is that the payload between activities has to be less than 1MB total. It's usually better to save the Bitmap to a file and pass the URI to the image to the next activity.

 protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.my_layout);
    Bitmap bitmap = getIntent().getParcelableExtra("image");
    ImageView imageView = (ImageView) findViewById(R.id.imageview);
    imageView.setImageBitmap(bitmap);
 }

这篇关于如何把图像中的包,并把它传递给另一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆