用c#中的Windows默认编辑器打开一个图像

本文关键字:图像 一个 中的 Windows 默认 编辑器 | 更新日期: 2023-09-27 18:09:32

在我的c#应用程序中,我想启动默认的图像编辑器来编辑图像。

当我使用System.Diagnostics.Process.Start("C:''image.png")时,它使用Windows照片查看器打开图像文件。

当我在Windows资源管理器中右键单击图像文件时,有一个"编辑"菜单项启动Microsoft Paint(默认情况下)。我想在我的应用程序中做同样的事情(即使用默认的图像编辑器打开文件)。

我不想硬编码MS油漆做Process.Start("mspaint.exe C:''image.png")。我更喜欢使用用户设置的默认图像编辑器程序(可以不同于MS Paint)。

有办法做到这一点吗?

谢谢弗兰克。

用c#中的Windows默认编辑器打开一个图像

您可以尝试使用动词edit启动进程。

ProcessStartInfo startInfo = new ProcessStartInfo("C:''image.png");
startInfo.Verb="edit";
Process.Start(startInfo);

如果你想用默认的windows编辑器在pictureBox中打开你的图像,试试这个;

//Create temporary file name
String TMP_IMAGE = "tempImage" +DateTime.Now.Millisecond +".bmp";
//get the folder of application
string PATH_APP =                
        System.IO.Path.GetDirectoryName(Application.ExecutablePath) + @"'tempImage'";
//Create a subFolder tempImage
Directory.CreateDirectory(PATH_APP);
//Save a new path in a variable
String NEW_PATH = PATH_APP + TMP_IMAGE;
//Save the image in the pictureBox in the new path and file name
pictureBox.Image.Save(NEW_PATH);
//Lunch the process with defaoul image editor in the comouter
ProcessStartInfo startInfo = new ProcessStartInfo(NEW_PATH);
Process.Start(startInfo);