我有一个SQlite数据库的项目。我将图像保存在文件夹中#34;照片" (进入调试文件夹)&他们在数据库中的名字(列" docpic")。当我连续点击时,相关图像将图像从数据库检索到picturebox1。我想通过点击picturebox1打开Windows照片查看器中的图像(在picturebox1中)。 怎么办呢?
我在picturebox1点击事件中使用此代码,但这不起作用:
if (pictureBox1.Tag != null)
{
System.Diagnostics.Process imageViewerProcess = new System.Diagnostics.Process();
imageViewerProcess.StartInfo.CreateNoWindow = false;
imageViewerProcess.StartInfo.FileName = "rundll32.exe";
imageViewerProcess.StartInfo.Arguments =
@"C:\WINDOWS\System32\shimgvw.dll,ImageView_Fullscreen "
+ pictureBox1.Tag.ToString();
imageViewerProcess.Start();
}
}
答案 0 :(得分:-1)
你在参数中遗漏了一些东西,因为它必须有正确的路径
如果您使用的是Windows 7 64位,请在参数代码行中将C:\Windows\system32
更改为C:\Windows\SysWOW64
。
所以它变成了:
imageViewerProcess.StartInfo.Arguments =
@"C:\Windows\SysWOW64\shimgvw.dll,ImageView_Fullscreen "+ pictureBox1.Tag.ToString();
您可以很快使用的所有代码的和 代替 :
简单用法:
System.Diagnostics.Process.Start(@"Directory + image name");
用于高级用法:
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(){
FileName = @"Directory + image name",
UseShellExecute = true,
Verb = "open"
});
另一种方式:
ProcessStartInfo startInfo = new ProcessStartInfo(@"Directory + image name");
startInfo.Verb = "open";
System.Diagnostics.Process.Start(startInfo);
并且当然将此更改为:
"Directory + image name"
到您的图片路径。
- 注意:必须是完整路径
例如:c:\folder\image.jpg
,
而不只是image.jpg