好吧,發生這種情況時,我正在編寫一個程序來拍攝一些截圖,並且在處理另一個進程正在使用的文件時遇到了一些困難,希望有人可以幫助我找到一種方法來「關閉」這個過程或讓我知道如何繼續。創建和刪除圖片/屏幕截圖
//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