简体   繁体   中英

C#,Winform - Setting arguments for Process class with Drawing.Image

I'm generating a picture in the picturebox

pictureBox1.Image = Image.FromStream(imageActions.GetImage(reader["ID_no"].ToString()));

It is working perfectly, but I am also creating an option for the user to edit it via any application (Let's example macromedia) So I created a button and did the thing.

private void button2_Click(object sender, EventArgs e)
        {
            Process photoViewer = new Process();
            photoViewer.StartInfo.FileName = @"C:\Program Files\Macromedia\Fireworks 8\Fireworks.exe";
            photoViewer.StartInfo.Arguments = ___________;
            photoViewer.Start();
        }

I understand that in the photoViewer.StartInfo.Arguments = you can put here the path of the image, but in my case. the image is stored in the Database as Image datatype. any ideas?

In order to load the image in an external application, you will first of all need to save it to the disk.

After the application has closed you will need to load the updated image to display to the user.

The Image property of the PictureBox control has a Save method you can call:

string tempFile = System.IO.Path.GetTempFileName();
pictureBox1.Image.Save(tempFile);

You can then pass the tempFile value as a parameter to the photoViewer process (I used MSPaint as a Proof of Concept):

Process photoViewer = new Process();
photoViewer.StartInfo.FileName = @"C:\Windows\System32\MSPaint.exe";
photoViewer.StartInfo.Arguments = tempFile;
photoViewer.EnableRaisingEvents = true;
photoViewer.Exited += photoViewer_Exited;
photoViewer.Start();

The two lines of photoViewer.EnableRaisingEvents = true and photoViewer.Exited += photoViewer_Exited; will tell your application when the photoViewer process exits, and this is a good place for you to load the image and display to your users.

private void photoViewer_Exited(object sender, EventArgs e)
{
    pictureBox1.Image = Image.FromFile(tempFile);
}

Note: string tempFile will need to be a class member variable so it can be accessed in the two functions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM