0

I'm trying to send an image to zoom activity from my main_activity.

I have a onclick function:

   case R.id.imageViewHero:

            String image = ViewHolder.this.post.getImageUrl();

            Intent intentv = new Intent(context, Zoom.class);

            Bundle extras = new Bundle();
            extras.putParcelable("imagebitmap", image);
            intentv.putExtras(extras);
            context.startActivity(intentv);

break;

the problem is the string image, I don't know what to do next to send it to zoom. Any ideas?

my zoom.class if needed:

public class Zoom  extends Activity {


@SuppressLint("NewApi")



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_zoom);

    Bundle extras = getIntent().getExtras();
    Bitmap bmp = (Bitmap) extras.getParcelable("imagebitmap");

    ImageView imgDisplay;
    Button btnClose;


    imgDisplay = (ImageView) findViewById(R.id.imgDisplay);
    btnClose = (Button) findViewById(R.id.btnClose);


    btnClose.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Zoom.this.finish();
        }
    });


    imgDisplay.setImageBitmap(bmp );

}

}

RGS
  • 4,062
  • 4
  • 31
  • 67

2 Answers2

1

In onClick method, you seem to send imageUrl. However in Zoom.java you're treating it as Bitmap.

You can use a library like Picasso to populate ImageView using Image URL

Sangharsh
  • 2,999
  • 2
  • 15
  • 27
1

The code is correct for most part except one mistake in making the Bitmap from the image URL.

You cannot make a Bitmap image from an image URL like you have done.

Its already been answered on StackOverflow. Check this link on how to convert an Image from an Image URL to a Bitmap - How to get bitmap from a url in android?

Basically, you are getting an Image URL from Intent which you are passing from the previous Activity, in the Zoom Activity, save it to a String variable, make Bitmap from it, set the Bitmap to the ImageView.

Community
  • 1
  • 1
Asutosh Panda
  • 1,463
  • 2
  • 13
  • 25
  • thank you for your answer! I edited my question with my try based on this link. if possible, to solve my question, could you see what is wrong in image2 there? (and if I'm in the right way) – RGS Feb 28 '17 at 14:47
  • 1
    You need to pass the Image URL to Zoom activity like the way you are doing. You need to make the Bitmap and set it in the Zoom Activity, not in the first Activity – Asutosh Panda Feb 28 '17 at 14:49