C# and image
-
Frnds, I have a desktop application(c# and SQL) which tries to get image from URL. What I did string imgg = PictureBoxImageAdding(dr.GetValue(0).ToString()); pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox1.Size = new System.Drawing.Size(142, 190); pictureBox1.Image = new Bitmap(imgg); It work fine with local path ie. d:/images/pics/xyz.jpg but not with http://www.xyz.com/images/pics/xyz.jpg Whats the SOLUTION.
-
Frnds, I have a desktop application(c# and SQL) which tries to get image from URL. What I did string imgg = PictureBoxImageAdding(dr.GetValue(0).ToString()); pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox1.Size = new System.Drawing.Size(142, 190); pictureBox1.Image = new Bitmap(imgg); It work fine with local path ie. d:/images/pics/xyz.jpg but not with http://www.xyz.com/images/pics/xyz.jpg Whats the SOLUTION.
Download the picture to a local (temporary) file, e.g. using HttpWebRequest from the System.Net namespace. Then load the temp file.
-
Frnds, I have a desktop application(c# and SQL) which tries to get image from URL. What I did string imgg = PictureBoxImageAdding(dr.GetValue(0).ToString()); pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox1.Size = new System.Drawing.Size(142, 190); pictureBox1.Image = new Bitmap(imgg); It work fine with local path ie. d:/images/pics/xyz.jpg but not with http://www.xyz.com/images/pics/xyz.jpg Whats the SOLUTION.
That's because you're creating a bitmap and that only understands files, not URIs or URLs. I think you probably want to just set the
ImageLocation
property toimgg
, or do aLoad()
, but haven't tried it so can't say for sure.Regards, Rob Philpott.
-
Frnds, I have a desktop application(c# and SQL) which tries to get image from URL. What I did string imgg = PictureBoxImageAdding(dr.GetValue(0).ToString()); pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox1.Size = new System.Drawing.Size(142, 190); pictureBox1.Image = new Bitmap(imgg); It work fine with local path ie. d:/images/pics/xyz.jpg but not with http://www.xyz.com/images/pics/xyz.jpg Whats the SOLUTION.
images have to be stored in memory or in a file. Valid file paths don't start with
http://
I use MemoryStream in such situations, seedownloadImage()
in CP Vanity[^]. :)Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
Frnds, I have a desktop application(c# and SQL) which tries to get image from URL. What I did string imgg = PictureBoxImageAdding(dr.GetValue(0).ToString()); pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox1.Size = new System.Drawing.Size(142, 190); pictureBox1.Image = new Bitmap(imgg); It work fine with local path ie. d:/images/pics/xyz.jpg but not with http://www.xyz.com/images/pics/xyz.jpg Whats the SOLUTION.
If you don't want to use a temp file, then: 1) create a web request 2) use the web request to get a web response 3) use GetResponseStream() to get stream of image 4) create image from stream 5) assign image to picturebox1.Image
Jack of all trades ~ Master of none.
-
Frnds, I have a desktop application(c# and SQL) which tries to get image from URL. What I did string imgg = PictureBoxImageAdding(dr.GetValue(0).ToString()); pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox1.Size = new System.Drawing.Size(142, 190); pictureBox1.Image = new Bitmap(imgg); It work fine with local path ie. d:/images/pics/xyz.jpg but not with http://www.xyz.com/images/pics/xyz.jpg Whats the SOLUTION.
You do not need to bother yourself with things like web requests to do this as others have suggested - this is completely unnecessary. As stated above just set ImageLocation to the URL you need.
Regards, Rob Philpott.