When I am trying to create image like
Image<Gray, Byte> testImage = new Image<Gray, Byte>("david.jpg");
When compiling it gaves An unhandled exceptio开发者_运维技巧n of type 'System.ArgumentException' occurred in System.Drawing.dll
exception.
But if I use
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK || result == DialogResult.Yes)
{
textBox1.Text = openFileDialog1.FileName;
}
Image<Gray, Byte> testImage = new Image<Gray, Byte>( textBox1.Text);
It works.Problem is that it cant find path? I am adding all .jpg files in project folder.
This is most likely because the image ("david.jpg") can't be found. There are two ways around this if you will always be using the image.
1/ Use the full file path ("C:\Main_Directory\Sub_Directory\David.jpg")
2/ If you wish to use just ("david.jpg")
Right Click on your project in the 'Solution Explorer' panel, (as you would add a new form or reference) select Add>Existing Item
Browse and locate your Image (Note:You may have to change what file type your looking for in the drop down box below object name. Once selected click Add.
In your 'Solution Explorer' panel you should have the image now in your project. Now the IMPORTANT step as you did with the OpenCV librarys (cv210.dll, cxcore210.dll etc) You must select the image and in the 'Properties' panel change the 'Copy to Output Directory' to either "copy if newer" or "copy always".
This should solve your problem if you are always going to use the image I would suggest option 2 as when you export the program to another user the image will be copied to the bin\deploy directory
Hope This helps
Chris
精彩评论