Rick Joe Rick Joe -4 years ago 78
Android Question

send image onclick to zoom activity

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 );

}


}

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download