简体   繁体   中英

How to convert a decode URL to bitmap and then shown the image in picturebox in winforms using c#.net

This is my URL

http://nry.hr2eazy.com//Modules//UserManagement//ImageLoader.ashx?PortalSettingId=1

I am using this code but the image not shown in PictureBox.

System.Net.WebRequest request =
   System.Net.WebRequest.Create("http://daikin.hr2eazy.com//Modules/UserManagement/ImageLoader.ashx?PortalSettingId=1");
System.Net.WebResponse response = request.GetResponse();
System.IO.Stream responseStream =
   response.GetResponseStream();
Bitmap bitmap2 = new Bitmap(responseStream);
pictureBox11.Image = bitmap2;

You could use the Load(string) method like:

myPictureBox.Load("https://i.picsum.photos/id/237/200/300.jpg?hmac=TmmQSbShHz9CdQm0NkEjx1Dyh_Y984R9LpNrpvH2D_U");

Your url is returning as plain text, so there's a little more work to load it, but that should do it:

HttpClient client = new HttpClient();
var response = client.GetAsync("http://nry.hr2eazy.com//Modules//UserManagement//ImageLoader.ashx?PortalSettingId=1").Result;
var imageStream = response.Content.ReadAsStreamAsync().Result;

Bitmap img = new Bitmap(imageStream);
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.Image = img;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM