Android - how can i transfer ImageView from one activity to another activity?

后端 未结 3 1111
独厮守ぢ
独厮守ぢ 2021-01-25 04:49

I have Activity1 which have one ImaveView including image preview. Once i press the button i go from Activity1 to Activity2. In Activity2 i do not have image preview but an opt

相关标签:
3条回答
  • 2021-01-25 04:57

    First of all you need to understand that when you are getting an image using the camera activity this way you are getting a thumbnail version of the taken image. in order to get a full size image it has to be saved, you can take a look at this blog post I wrote on this matter for more information:

    Use Camera Activity for Thumbnail and Full Size Image

    Now for your question, I think that the best option would be to save this image to a file (described in the guide) and pass an extra to the following activity with the string path of the image.

    0 讨论(0)
  • 2021-01-25 05:02

    There are many way to solve this problem. And here are 2 simple ways:

    The first, you can read more about SharedPreferences

    The second, you can putExtra bitmap from this Activity to another activity like this:

    putExtra:

    intent.putExtra(BITMAP_SHARED_KEY, yourBitmap);
    startActivity(intent);
    

    getBitmap which you've shared

    Bitmap bitmap = (Bitmap) intent.getParcelableExtra(BITMAP_SHARED_KEY); // BITMAP_SHARED_KEY = "bitmap_shared_key"
    
    0 讨论(0)
  • 2021-01-25 05:11

    Simple Way Use this

    1. First Activity

      Bitmap bitmap = BitmapFactory.decodeResource(getResources(), 
      R.drawable.men_icon);
      Bundle extras = new Bundle();
      Intent intent=new Intent(FirstActivity.class,SecondActivity.class);
      extras.putParcelable("Bitmap", bitmap);
      intent.putExtras(extras);
      startActivity(intent);
      
    2. Second Activity

       ImageView iv_photo=(ImageView)findViewById(R.id.iv_photo);
       Bundle extras = getIntent().getExtras();
       Bitmap bmp = (Bitmap) extras.getParcelable("Bitmap");
       iv_photo.setImageBitmap(bmp);
      
    0 讨论(0)
提交回复
热议问题