Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to convert a decode url to bitmap and then the image should shown in picturebox..pls give some idea ji

This is my code....Picture box shows empty

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;

What I have tried:

This is my Url

http://nry.hr2eazy.com//Modules//UserManagement//ImageLoader.ashx?PortalSettingId=1">http:/daikin.hr2ezy.com/ + "/Modules//UserManagement//ImageLoader.ashx" + "?PortalSettingId=1
Posted
Updated 10-Feb-21 20:11pm
v2

1 solution

If you had bothered to do what I told you last time you posted this question: Load a image from URL to picture box using c#.net[^] you would have seen what was going on: it's a PNG image. And a quick test with your code shows it works. Except ... you didn't read the documentation: Image.FromStream Method (System.Drawing) | Microsoft Docs[^] which clearly states:
Remarks
You must keep the stream open for the lifetime of the Image.
You don't. You specifically Dispose the stream once you have created the Bitmap, which means the image is no longer valid.

Go back to your existing code, create Bitmap object, use the debugger to prove it is correct - as I suggested yesterday - and then copy the image to a new bitmap before you Dispose the Stream.

A quick check with the debugger would have shown you that the image was valid inside the using block and invalid outside it a day ago ... so why didn't you try using it?
 
Share this answer
 
Comments
Member 15028582 11-Feb-21 2:33am    
Actually Sir....I am using the debug tool what u have said
but the code executes properly didn't get any error msg.....But picturebox is shown as empty
OriginalGriff 11-Feb-21 3:15am    
not all code faults give error messages - that's why you use the debugger to see exactly what *is* going on. It lets you look at (or even change) variables while you code is executing, run your app line by line, and so on.
Error messages just tell you a fatal error happened at some point in the past, they are a tiny percentage of actual bugs!

Learn to use the debugger - it will save you hours of work and hair pulling frustration!
Member 15028582 11-Feb-21 3:33am    
Actually got the output ji....... PictureBox SizeMode = StretchImage....Image is to loong so that only it doesnot shown....now it works....Sry actually this is a silly mistake....Thanks for ur support ji

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900