我有以下代码来创建屏幕截图,但我面临的唯一问题是它打开命令提示符并让用户关闭它,我可以隐藏/删除此命令提示符吗?
private const int TIMEOUT = 30000;
private const string TMP_NAME = "TMP_SHOT1.png";
protected void Page_Load(object sender, EventArgs e)
{
theImage.ImageUrl = GetImage("http://www.google.com", "MyImage",
Server.MapPath("~"),
Convert.ToInt32("400"),
Convert.ToInt32("400")
);
}
public string GetImage(string url, string name,
string rootDir, int width, int height)
{
try
{
string fileName = rootDir + "\\" + TMP_NAME;
GenerateScreenShot1(url, rootDir);
System.Drawing.Image thumbImage =
System.Drawing.Image.FromFile(fileName);
fileName = rootDir + "\\" + name + ".png";
if (File.Exists(fileName))
File.Delete(fileName);
thumbImage.Save(fileName, ImageFormat.Png);
return name + ".png";
}
catch (Exception ex)
{
return null;
}
}
public void GenerateScreenShot1(string url1, string rootDir1)
{
string arguments = url1 + " " + rootDir1 + "\\" + TMP_NAME;
Process myProcess = new Process();
myProcess.EnableRaisingEvents = false;
myProcess.StartInfo.RedirectStandardOutput = false;
myProcess.StartInfo.CreateNoWindow = false;
myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.FileName = rootDir1 + "\\" + "IECapt.exe";
myProcess.StartInfo.Arguments = arguments;
myProcess.Start();
myProcess.WaitForExit();
myProcess.Close();
myProcess.Dispose();
}
要运行上述代码,您需要将IECapt.exe放在根文件夹中。
答案 0 :(得分:2)
试试这个
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
也
要使用ProcessWindowStyle.Hidden,ProcessStartInfo.UseShellExecute属性必须为false。
从这里开始 http://msdn.microsoft.com/en-us/library/system.diagnostics.processwindowstyle.aspx
答案 1 :(得分:1)
更改行
myProcess.StartInfo.CreateNoWindow = false;
与
myProcess.StartInfo.CreateNoWindow = true;
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.createnowindow.aspx
答案 2 :(得分:0)
尝试设置myproces.StartInfo.UseShellExecute = false;