According to the following link and my console application, the DrawToBitmap method DrawToBitmap not take opacity into account.
Evidence link: http://social.msdn.microsoft.com/Forums/vstudio/en-US/e9704309-0c52-442d-80e0-2f8393dcd313/webbrowser-opacity-problem-
My HTML is: http://fiddle.jshell.net/L37TC/
<div id="fader" style="background-color: #ff0000">ffff</div> <div style="background-color: blue; opacity:0;filter:alpha(opacity=0);">HIDDEN TEXT!</div> SomeText
My C # console code:
var bmp = new Bitmap(640,480, PixelFormat::Format32bppArgb) var web = (System.Windows.Forms.Control)sender; web.DrawToBitmap(bmp, Rectangle(0, 0, 640,480));
So, I'm looking for an alternative .NET built-in solution ( without CEF, Awesomium or any extension ), just a .NET built-in function to fix a bug or an alternative solution to take a screenshot of the web URL in my console application.
If I create a WebBrowser window that is visible to my client and use CopyFromScreen , the opacity is respected and HIDDEN TEXT not displayed, as much as I would like the WebBrowser window WebBrowser be displayed on the desktop screen.
I am looking for a built-in solution to take a screenshot from a hosted URL in a question without HIDDEN TEXT . In other words, the solution corresponds to opacity .
EDIT1: all the pixels in my Bitmap class (.NET format is not BMP) have an alpha value of 255. Therefore, the problem is NOT with the file format. I tried PNG and any other supported .NET format.
Full source code (console template, add links to System.Drawing and System.Windows.Forms
class Program { static System.Windows.Forms.WebBrowser w = new System.Windows.Forms.WebBrowser(); [STAThread] static void Main(string[] args) { w.Navigate("http://fiddle.jshell.net/L37TC/show/"); w.DocumentCompleted += w_DocumentCompleted; System.Windows.Forms.Application.Run(); while (true) Console.Read(); } static void w_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e) { var bmp = new System.Drawing.Bitmap(w.Width, w.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); ((System.Windows.Forms.Control)w).DrawToBitmap(bmp, new System.Drawing.Rectangle(0, 0, w.Width, w.Height)); for (int i = 0; i < w.Width; i++) for (int j = 0; j < w.Height; j++) if (bmp.GetPixel(i, j).A != 255) { Console.WriteLine("Alpha != 255"); return; } Console.WriteLine("All pixels have alpha value of 255"); bmp.Save(@"d:\ss.png", System.Drawing.Imaging.ImageFormat.Png);