【问题标题】:Bitmap looks different after ColorMatrix transform on XP and Win7在 XP 和 Win7 上进行 ColorMatrix 变换后的位图看起来不同
【发布时间】:2011-08-29 06:06:10
【问题描述】:

我希望我的 webBrowser 看起来透明。我的代码如下所示:

        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 控件周围的圆形框架)。

以前,当我不使用 ColorMatrix 时,我是这样做的:

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。

【问题讨论】:

  • win xp 对透明 png 的支持不是有点不稳定吗?
  • 你是对的 Co​​dingBarfield!我用 chrome 和 IE silisoftware.com/png_alpha_transparency 打开了那个网站。 Png 在 XP 上的 IE 上看起来很糟糕(它的版本是 6)。这就是win7没问题的原因,因为它有更新版本的IE。
  • 任何想法如何将更新的 IE6 模块附加到我的程序中,以便在任何 PC 上看起来都很好(无论用户拥有哪个版本的 IE)?回答,我会设置为最佳答案。

标签: c# browser gdi+ transparency colormatrix


【解决方案1】:

我将我的 IE 浏览器更新到版本 8,并且运行良好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-01
    • 2011-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-09
    • 2017-08-29
    • 1970-01-01
    相关资源
    最近更新 更多