Open an image with the Windows default editor in C#

后端 未结 2 1824
别跟我提以往
别跟我提以往 2020-12-11 19:42

In my C# application, I would like to launch the default image editor to edit an image.

When I\'m using System.Diagnostics.Process.Start(\"C:\\\\image.png\")

2条回答
  •  悲哀的现实
    2020-12-11 19:55

    If you want open your image in the pictureBox by a Default Winndows Editor try this;

    //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);
    

提交回复
热议问题