从picturebox(C#)中删除图像引用
从picturebox(C#)中删除图像引用,c#,lilypond,C#,Lilypond,“C:\ProgramFiles(x86)\LilyPond\usr\bin\LilyPond.exe”--png tmp.ly命令创建tmp.png。当我第一次按a键时,MyProcess返回0,但next-始终返回1。我认为问题在于覆盖MyPictureBox使用的文件tmp.png,但我不知道如何修复它。您能帮助我吗?据我所知,lilypond没有提供使用命令行参数进行覆盖的选项。若我是对的,那个么你们可以在MyProcess开始之前包括要删除的代码,然后是png文件(若存在) using
“C:\ProgramFiles(x86)\LilyPond\usr\bin\LilyPond.exe”--png tmp.ly
命令创建tmp.png
。当我第一次按a
键时,MyProcess返回0,但next-始终返回1。我认为问题在于覆盖MyPictureBox使用的文件tmp.png
,但我不知道如何修复它。您能帮助我吗?据我所知,lilypond没有提供使用命令行参数进行覆盖的选项。若我是对的,那个么你们可以在MyProcess开始之前包括要删除的代码,然后是png文件(若存在)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace MyProject
{
public partial class MyForm : Form
{
Process MyProcess;
public MyForm()
{
InitializeComponent();
}
private void MyForm_KeyPress(object sender, KeyPressEventArgs e)
{
switch (e.KeyChar)
{
case 'a':
this.MyPictureBox.Image = null;
this.MyProcess = new Process();
this.MyProcess.StartInfo =
new ProcessStartInfo("\"C:\\Program Files (x86)\\LilyPond\\usr\\bin\\lilypond.exe\"", "--png tmp.ly");
this.MyProcess.Start();
this.MyProcess.WaitForExit();
this.MyPictureBox.Image = new Bitmap("tmp.png");
break;
default:
break;
}
}
}
}
删除它(如果存在)。检查这篇文章:我应该在哪里插入代码?在
this.MyPictureBox.Image=null之后代码>在私有无效MyForm_按键(对象发送者,按键事件参数e)
?在“MyProcess.Start();”之前,我得到了IOException(进程无法访问该文件>,因为它正被另一个进程使用。
)。让我们假设在“案例a”之后添加它:“很抱歉,您的建议并不能解决我的问题,因为问题在于MyPictureBox使用png文件。我发现最好的方法是使用MyPictureBox.Image.Dispose()
方法。使用Image加载.png怎么样?“Image=Image.FromFile(路径);MyPictureBox.Image=Image;”
if (System.IO.File.Exists(path))
{
System.IO.File.Delete(path);
}