According to following link and my console application the method DrawToBitmap
doesn't respect opacity.
Proof link:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/e9704309-0c52-442d-80e0-2f8393dcd313/webbrowser-opacity-problem-
My HTML code : 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 alternative .NET built-in solution (no CEF, Awesomium, or any extension please) just a built-in feature of .NET to fix the bug or alternative solution to take screenshot of a web URL in my console application.
If I make WebBrowser
window visible to my client and use CopyFromScreen
the opacity is respected and HIDDEN TEXT
isn't showing, how ever I don't want to make WebBrowser
window visible to desktop screen.
I'm looking for a built-in solution to take a screenshot from posted URL in the question without HIDDEN TEXT
. In other words a solution to respect opacity
.
EDIT1: All pixels in my Bitmap
class
(.NET class not BMP format) has alpha value of 255. So the problem is NOT with file format. I have tried PNG and any other .NET supported format.
Complete source code (Console Template, Need to add references 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);
// HIDDEN TEXT has opcity of 0 but it's appearing in image
}
}
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…