0

I'm trying to have an image load in my winform through a TCP message.

At the moment I have a my program set to look in the required directory via the following. This line is held with in a TCP class I've set up:

Image _imageName = Image.FromFile("C:\\Image\\");

What my tcp command will do is send the following string line:

IMG Cat

The first 3 letters aren't important, but need to be in there. With this tcp command I've set up a switch statement that will act depending on those first three letters. So, my new _image name line looks like the following:

Image _imageName = Image.FromFile("C:\\Image\\" + splitString[1]);

The value of _imageName is then stored in a getter called Picture;

Inside my Image class I'm setting the file to be displayed like this:

PictureBox _picBox = new PictureBox();
_picBox.Image = Image.FromFile(_tcp.Picture);

However, I get the following errors:

The best overloaded method match for "System.Drawing.Image.FromFile(string) has some invalid arguments Argument 1: cannot convert 'System.Drawing.Image' to 'string;

The line that is highlighted is the _picBox.Image line. I've tried googleing an answer. Casting the command as both an Image and a float, changing my getter. But nothing is working.

Does anyone know how I can fix this?

3
  • It's not 100% clear what your code does, but seems like this might work: _picBox.Image = _tcp.Picture; put it instead of last line.
    – Anri
    Feb 4, 2013 at 11:02
  • Son of a gun. You are correct. Thank you.
    – N0xus
    Feb 4, 2013 at 11:08
  • You are welcome. Posted it as answer.
    – Anri
    Feb 4, 2013 at 11:16

1 Answer 1

0

In this lines you are trying to create Image form another Image instance.

 PictureBox _picBox = new PictureBox();
_picBox.Image = Image.FromFile(_tcp.Picture);

While FromFile method accepts string path to image file you want to load. Fix it like this:

 PictureBox _picBox = new PictureBox();
_picBox.Image = _tcp.Picture;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.