2010-04-29 62 views
5

每個人。這可能有一個簡單的解決方案,但我似乎無法找到一個。我正在玩弄Visual Studio 2010附帶的WPF中的WebBrowser控件,並試圖以編程方式將可能出現在網頁上的圖像保存到磁盤。從WPF的WebBrowser控件保存圖像 - 你怎麼做?

非常感謝提前! 運氣

回答

6

添加System.Drawing作爲參考,並執行該方法中的以下算子的研究應該捕獲圖像:

Rect bounds = VisualTreeHelper.GetDescendantBounds(browser1); 

System.Windows.Point p0 = browser1.PointToScreen(bounds.TopLeft); 
System.Drawing.Point p1 = new System.Drawing.Point((int)p0.X, (int)p0.Y); 

Bitmap image = new Bitmap((int)bounds.Width, (int)bounds.Height); 
Graphics imgGraphics = Graphics.FromImage(image); 

imgGraphics.CopyFromScreen(p1.X, p1.Y, 
          0, 0, 
          new System.Drawing.Size((int)bounds.Width, 
                 (int)bounds.Height)); 

image.Save("C:\\a.bmp", ImageFormat.Bmp);