1
我希望我的webBrowser看起来透明。我的代码如下所示:XP和Win7上的ColorMatrix转换后,位图看起来不同
Bitmap backGroungImage = new Bitmap(Width, Height);
myWebBrowser1.Visible = false;
DrawToBitmap(backGroungImage, new Rectangle(0, 0, backGroungImage.Width, backGroungImage.Height));
myWebBrowser1.Visible = true;
Bitmap backGroundImage2 = new Bitmap(myWebBrowser1.Width - 20, myWebBrowser1.Height - 20);
Graphics.FromImage(backGroundImage2).DrawImage(backGroungImage, new Rectangle(0, 0, backGroundImage2.Width, backGroundImage2.Height), new Rectangle(SystemInformation.FrameBorderSize.Width + myWebBrowser1.Location.X + 10, SystemInformation.CaptionHeight + SystemInformation.FrameBorderSize.Height + 10 + myWebBrowser1.Location.Y, myWebBrowser1.Width - 20, myWebBrowser1.Height - 20), GraphicsUnit.Pixel);
ImageAttributes imageAttributes = new ImageAttributes();
ColorMatrix colorMatrix = new ColorMatrix(new float[][]
{
new float[] {1, 0, 0, 0, 0},
new float[] {0, 1, 0, 0, 0},
new float[] {0, 0, 1, 0, 0},
new float[] {0, 0, 0, 1f - 230f/255f, 0},
new float[] {0, 0, 0, 0, 1}
});
imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
Bitmap backGroundImage3 = new Bitmap(backGroundImage2.Width, backGroundImage2.Height);
Graphics.FromImage(backGroundImage3).DrawImage(backGroundImage2, new Rectangle(0, 0, backGroundImage3.Width, backGroundImage3.Height), 0, 0, backGroundImage2.Width, backGroundImage2.Height, GraphicsUnit.Pixel, imageAttributes);
backGroundImage3.Save("d:\\BG.png", ImageFormat.Png);
然后我在html代码中使用“d:\ BG.png”。
它在我的Windows 7上正常工作,但在Windows XP中它更黑,不适合在GDI +中绘制的alpha = 230(我的意思是围绕WebBrowser控件的圆框)绘制的其他白色元素。
之前,当我没有使用嘉洛斯,我这样做:
int alpha = 230;
Color c1, color = Color.FromArgb(255, 255, 255);
for (int x = 0; x < d.Width; x++)
for (int y = 0; y < d.Height; y++)
{
c1 = d.GetPixel(x, y);
d.SetPixel(x, y, Color.FromArgb(((255 - alpha) * c1.R + alpha * color.R)/255, ((255 - alpha) * c1.G + alpha * color.G)/255, ((255 - alpha) * c1.B + alpha * color.B)/255));
}
而且在两个操作系统看起来很棒,但速度很慢。 我希望它看起来与GDI +中的alpha 230颜色一样白,并且速度很快。 顺便说一句。有没有一种方法可以将WebBrowser放入背景图片,然后使其透明?
PS。它是从两台计算机上的相同文件安装的Visual Studio 2010 Professional和.NET Framework 4。
是不是透明png支持win xp有点摇摆不定? – CodingBarfield
你是对的CodingBarfield!我用chrome和IE打开了该网站http://www.silisoftware.com/png_alpha_transparency/。 XP在XP上看起来非常糟糕(它的版本是6)。这就是为什么win7可以,因为它有更新版本的IE。 –
任何想法如何将IE6模块加入到我的程序中,因此它可以在任何PC上看起来不错(不管用户使用哪个版本的IE)?回答,我会将其设置为最佳答案。 –