C#、Winform - 为进程 class 和 Drawing.Image 设置参数

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

我正在 picturebox

中生成图片
pictureBox1.Image = Image.FromStream(imageActions.GetImage(reader["ID_no"].ToString()));

它工作得很好,但我也创建了一个选项供用户通过任何应用程序编辑它(让我们以 macromedia 为例)所以我创建了一个按钮并做了这件事.

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();
        }

我知道在 photoViewer.StartInfo.Arguments = 你可以把图片的路径放在这里,但在我的例子中。图像以 Image 数据类型存储在数据库中。有什么想法吗?

为了在外部应用程序中加载图像,您首先需要将其保存到磁盘。

应用程序关闭后,您需要加载更新的图像以显示给用户。

PictureBox控件的Image属性有一个Save方法可以调用:

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

然后您可以将 tempFile 值作为参数传递给 photoViewer 进程(我使用 MSPaint 作为概念验证):

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

photoViewer.EnableRaisingEvents = truephotoViewer.Exited += photoViewer_Exited; 这两行将告诉您的应用程序 photoViewer 进程何时退出,这是您加载图像并显示给用户的好地方。

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

注意:string tempFile 需要是一个 class 成员变量,以便可以在两个函数中访问它。