[英]Capturing windows form into image
我知道這個問題已經回答過了。 但是,沒有一個答案是正確的。 如何捕獲Windows窗體的圖像並將其保存。 我用這個:
Bitmap bmp = new Bitmap(this.Width, this.Height);
this.DrawToBitmap(bmp, new Rectangle(Point.Empty, bmp.Size));
bmp.Save(@"C://Desktop//sample.png",ImageFormat.Png);
但得到錯誤:
GDI +中發生一般錯誤
我還閱讀了有關此錯誤的信息,但沒有任何建議對我有用! 請幫忙
問題出在bmp.Save(@"C://Desktop//sample.png",ImageFormat.Png);
。
首先,它必須是@“ C:\\ Desktop \\ sample.png”,您不需要使用逐字字符串轉義任何內容。
其次,請確保路徑正確,並且您具有寫入權限。
正如Sayse所指出的,第三點是配置位圖。
using(Bitmap bmp = new Bitmap(this.Width, this.Height))
{
this.DrawToBitmap(bmp, new Rectangle(Point.Empty, bmp.Size));
bmp.Save(@"C:\Desktop\sample.png",ImageFormat.Png); // make sure path exists!
}
您的路徑格式錯誤。 應該:
bmp.Save("C:\\Desktop\\sample.png",ImageFormat.Png);
更重要的是-檢查文件夾是否存在
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.