C# :Emgu CV 创建图像问题
当我尝试创建像
Image<Gray, Byte> testImage = new Image<Gray, Byte>("david.jpg");
编译时这样的图像时,它给出了 System.Drawing.dll 中出现类型为“System.ArgumentException”的未处理异常异常。 但如果我使用
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);
它就可以了。问题是它找不到路径?我正在项目文件夹中添加所有 .jpg 文件。
When I am trying to create image like
Image<Gray, Byte> testImage = new Image<Gray, Byte>("david.jpg");
When compiling it gaves An unhandled exception 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这很可能是因为找不到图像(“david.jpg”)。如果您始终使用该图像,有两种方法可以解决此问题。
1/ 使用完整文件路径 ("C:\Main_Directory\Sub_Directory\David.jpg")
2/ 如果您只想使用 ("david.jpg"),
请在“解决方案资源管理器”面板中右键单击您的项目,(就像添加新表单或参考一样)选择“添加”>“现有项目
浏览”并找到您的图像(注意:您可能必须在对象名称下方的下拉框中更改要查找的文件类型。选择后单击“添加”。
在您的在“解决方案资源管理器”面板中,您的项目中现在应该有图像了。现在,重要的步骤就像您对 OpenCV 库(cv210.dll、cxcore210.dll 等)所做的那样,您必须选择图像并在“属性”面板中更改“复制到输出目录”为“如果较新则复制”或“始终复制”,
如果您总是要使用该图像,这应该可以解决您的问题,我建议使用选项 2,因为当您将程序导出到另一个用户时,该图像将。复制到 bin\deploy 目录
希望这对
Chris有帮助
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