How to pass image data from one activity to another activity?

后端 未结 9 683
一生所求
一生所求 2020-11-30 14:26

I am using two activities. One activity displays images in a GridView and by clicking on a particular image in that GridView it should display the

相关标签:
9条回答
  • 2020-11-30 14:58

    Try passing id related to image through intent.putExtra(), and receive it through bundle on launched activity.

    0 讨论(0)
  • 2020-11-30 14:59

    You pass parameters to an Activity in an Intent. If the image comes from a file, pass the path String, otherwise pass the Bitmap

    startActivity(new Intent(this, YourActivity.class).putExtras(new Bundle().putParcelable("bitmap", Bitmap)))
    
    0 讨论(0)
  • 2020-11-30 14:59

    Once an item of Grid View is clicked, get the clicked item and pass it to next activity as an argument through PutExtra. In the next activity retrieve the image from extras and display it to user

    0 讨论(0)
  • 2020-11-30 15:09

    in Activity convert the image to ByteArray and append it to the intent as

    intent.putExtra("img",<ByteArray>);
    

    then startActivity B.

    In Activity B

    Bitmap bm = BitmapFactory.decodeByteArray(getIntent().getByteArrayExtra("img"), 0, getIntent().getByteArrayExtra("img").length);
    

    This way you can pass image between activity.

    0 讨论(0)
  • 2020-11-30 15:12

    To pass the data between two activities:

    bytes[] imgs = ... // your image
    Intent intent = new Intent(this, YourActivity.class);
    intent.putExtra("img", imgs);
    startActivity(intent);
    

    Then in YourActivity:

    bytes[] receiver = getIntent().getExtra("imgs");
    

    Also go thro this link which wil also help u.
    Here u can know how to convert bitmap to bytes

    0 讨论(0)
  • 2020-11-30 15:13

    This is my process: it's so good. Activity1:

    ByteArrayOutputStream stream=new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG,100,stream);
        byte[] byteArray=stream.toByteArray();
        Intent intent = new Intent(getApplicationContext(), FrameActivity.class);
        intent.putExtra("Image", byteArray);
        startActivity(intent);
    

    in FrameActivity.class

    collageView = (CollageView) findViewById(R.id.btn_collage);
        byte[] byteArray = getIntent().getByteArrayExtra("Image");
        Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
        collageView.setImageBitmap(bmp);
    
    0 讨论(0)
提交回复
热议问题