how to pass images through intent?

后端 未结 1 2031
遇见更好的自我
遇见更好的自我 2020-12-03 19:41

First class

public class ChooseDriver extends Activity implements OnItemClickListener {

  private static final String rssFeed   = \"http://         


        
相关标签:
1条回答
  • 2020-12-03 20:37

    You can pass it as a byte array and build the bitmap for display on the next screen. but using intent we can send small images like thumbnails,icons etc.else it will gives bind failure.

    Sender Activity

    Intent _intent = new Intent(this, newscreen.class);
    Bitmap _bitmap; // your bitmap
    ByteArrayOutputStream _bs = new ByteArrayOutputStream();
    _bitmap.compress(Bitmap.CompressFormat.PNG, 50, _bs);
    _intent.putExtra("byteArray", _bs.toByteArray());
    startActivity(_intent);
    

    Receiver Activity

    if(getIntent().hasExtra("byteArray")) {
    ImageView _imv= new ImageView(this);
    Bitmap _bitmap = BitmapFactory.decodeByteArray(
            getIntent().getByteArrayExtra("byteArray"),0,getIntent().getByteArrayExtra("byteArray").length);        
    _imv.setImageBitmap(_bitmap);
    }
    
    0 讨论(0)
提交回复
热议问题