我在绘画中打开图像之前从图像查看器中删除文件名。
这是我的代码..
private void btnEditImage_Click(object sender, RoutedEventArgs e)
{
if (File.Exists(Helper.DefaultPath + listImages[count].Path))
{
SetNullImage();
string editPath = Helper.DefaultPath + listImages[count].Path;
if (File.Exists(editPath))
{
Process my = new Process();
my.StartInfo.FileName = "mspaint.exe";
my.StartInfo.Arguments = "\"" + editPath + "\"";
my.StartInfo.CreateNoWindow = true;
my.EnableRaisingEvents = true;
my.Exited += new EventHandler(myProcess_Exited);
my.Start();
}
}
}
private void myProcess_Exited(object sender, System.EventArgs e)
{
Dispatcher.Invoke(new Action(() =>
{
SetImage();
}));
}
见图片
感谢...
答案 0 :(得分:0)
在您致电SetImage()
方法时,请确保您使用的是Image.FromFile()
方法。如果您使用那个,请使用Bellow代码而不是
private Bitmap SetImage(){
pictureBox1.Image = GetImageFromPath(ImagePath)
}
private Bitmap GetImageFromPath(string Path)
{
using (StreamReader streamReader = new StreamReader(Path))
{
using (Bitmap tmpBitmap = (Bitmap)Bitmap.FromStream(streamReader.BaseStream))
{
return tmpBitmap;
}
}
}