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?
In this lines you are trying to create
Imageform anotherImageinstance.While
FromFilemethod acceptsstringpath to image file you want to load.Fix it like this: