好吧,发生这种情况时,我正在编写一个程序来拍摄一些截图,并且在处理另一个进程正在使用的文件时遇到了一些困难,希望有人可以帮助我找到一种方法来“关闭”这个过程或让我知道如何继续。创建和删除图片/屏幕截图
//Create a new bitmap.
var bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height,
PixelFormat.Format32bppArgb);
// Create a graphics object from the bitmap.
var gfxScreenshot = Graphics.FromImage(bmpScreenshot);
// Take the screenshot from the upper left corner to the right bottom corner.
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
Screen.PrimaryScreen.Bounds.Y,
0,
0,
Screen.PrimaryScreen.Bounds.Size,
CopyPixelOperation.SourceCopy);
// Save the screenshot to the specified path that the user has chosen.
//bmpScreenshot.Save(nomeScreen + ".jpeg", ImageFormat.Jpeg);
bmpScreenshot.Save(@"c:\temp\"+nomeScreen+".jpeg", ImageFormat.Jpeg);
count++;
nomeScreen = "S"+Convert.ToString(count);
这是我(我知道,可怜的编程技能)需要几个截图,不过后来我想他们从地方被删除,其中我将它们存储
http://gyazo.com/4b50945b0d157d082f7897e34a705560
这是它发生的一个截图。如何“关闭”位图?该程序迄今为止唯一的动作是截图并删除它们。
string pathString = "C:\\temp";
DirectoryInfo d = new DirectoryInfo(pathString);
foreach (var k in d.GetFiles("*.jpeg"))
{
File.Delete(pathString+"\\" + k);
}
你似乎没有关闭位图,我想像可能出现有错误,但在那里你真正得到它是不明错误 – Sayse 2014-12-19 07:16:05
@Sayse http://gyazo.com/4b50945b0d157d082f7897e34a705560该程序只需要截图并将其保存到该文件夹中。在获取这些截图之后,我想删除它们,那是错误出现时,我尝试过Dispose方法,该如何关闭位图? – abr 2014-12-19 07:25:35
我的意思是处置,但你最好使用'using'块。 – Sayse 2014-12-19 07:53:25