[RESOLVED] Strange Error loading image into PictureBox
I'm experiencing a very strange error that I can't manage to fix and need some help from anyone with suggestions please.
I have a PictureBox on my main form. When a user clicks an entry on a listbox is loads an image from a webserver into the picturebox.
To ensure you understand the way it all works:
Server:
Linux SuSe Server, running Apache Webserver and MySQL Database.
Images are saved to server via a network share. Only a few select computers can access this share, this is by design. The images are saved to a directory which is listed by Apache. I.e. If you browse to the server using internet explorer or firefox you can access the images.
Users:
Most users are in the same building accessing the server over a 10/100 lan. There are a few users who access it via internet.
Problem:
Users on the network have an issue where it cannot load the image into the picturebox. I get the wonderfully helpful error of "Parameter not valid". This error only appears sometimes. On starting the program it's almost always every second time. But even if it works initially, if the program is left running for a few minutes it then starts doing this as well.
My original code was:
Code:
public void ShowLeadImage(System.Windows.Forms.PictureBox picBox, string ImageDir)
{
//display image for lead
long batchID = ReturnScanBatchID(ImageDir);
string imageLocation = globals.Instance.serverImageDir + batchID.ToString() + "/";
imageLocation += ImageDir + ".jpg";
try
{
picBox.Load(imageLocation);
}
catch (Exception ex)
{
ErrorLog(2, "Error Loading Image [" + imageLocation + "]", ex.Message);
}
}
I have tried changing it to this incase it was the way that the picturebox was trying to load an image:
Code:
public void ShowLeadImage(System.Windows.Forms.PictureBox picBox, string ImageDir)
{
//display image for lead
long batchID = ReturnScanBatchID(ImageDir);
string imageLocation = globals.Instance.serverImageDir + batchID.ToString() + "/";
imageLocation += ImageDir + ".jpg";
try
{
Stream ImageStream = new WebClient().OpenRead(imageLocation);
Image img = Image.FromStream(ImageStream);
img.Save(@"C:\temp.jpg");
picBox.Load(@"C:\temp.jpg");
}
catch (Exception ex)
{
globals.Instance.ErrorLog(2, "Error Loading Image [" + imageLocation + "]", ex.Message);
}
}
I tried pulling the image directly into the picturebox from the stream. Same error. Tried saving it to the c drive first and then loading it and the error still occurs (error occurs before it manages to save it to harddrive).
The images are all valid. They are not corrupt. The fact that it sometimes works and sometimes doesn't baffles me. If I open up IE on the pc and put the path in, it loads the image fine. I can refresh to my hearts content and the image is fine.
All users running the program via internet are working fine. It never does this for them.
My current suspicion is that there could be an issue with apache on the linux server but there are no logs on the server to indicate anything suspicious.
Does anyone have any suggestions as to what could be wrong, or how else I could diagnose the problem?
Re: Strange Error loading image into PictureBox
Just a suggestion, but maybe you can try using a webbrowser control rather than the picturebox. Then set the webbrowser.documenttext to something like:
Code:
<img src='mywebserver/images/someimage.jpg'>
Re: Strange Error loading image into PictureBox
I've tried this now after your suggestion and I still have the same problem.
Works every second time only...
I'm running out of things to try... :(
Re: Strange Error loading image into PictureBox
Ok, I found the problem. In the windows system logs there was one of these errors corresponding to each time I encountered a problem:
"The redirector failed to determine the connection type"
This lead me to microsoft, http://support.microsoft.com/kb/315244 which didn't help much, since basically they state "This error message is only informational. You can safely ignore it."
I have set the linux firewall box with a static dns entry for the server so that computers on the network can access it using the same address as the remote computers.
e.g. Computers on network: server.domainname = 192.168.0.100
Remote Computers: server.domainname = 41.51.234.16
There's obviously some problem with the way XP is resolving the names for the computers on the network since it all works fine if I set it to use an IP address instead of a FQDN. It's really strange since it never has a problem using the FQDN for the mysql database connection, only for the images.
Anyways, I've got around the problem by putting in a registry setting so tha t users can specify a server name or ip address for connecting.