开发者

Bitmap looks different after ColorMatrix transform on XP and Win7

开发者 https://www.devze.com 2023-03-31 22:56 出处:网络
I want my webBrowser to look transparent. My code looks like that: Bitmap backGroungImage = new Bitmap(Width, Height);

I want my webBrowser to look transparent. My code looks like that:

        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, 开发者_JAVA技巧0, backGroundImage3.Width, backGroundImage3.Height), 0, 0, backGroundImage2.Width, backGroundImage2.Height, GraphicsUnit.Pixel, imageAttributes);

        backGroundImage3.Save("d:\\BG.png", ImageFormat.Png);

and then I use "d:\BG.png" in html code.

It works fine on my windows 7, but on windows XP it's darker, doesn't fit other white elements drawn in GDI+ with alpha = 230 (I mean round frame around the WebBrowser control).

Before, when I didn't use ColorMatrix, I did that:

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));
            }

And looked great on both OSes, but was very slow. I want it to look the same as white color with alpha 230 in GDI+ and to be fast. BTW. is there a way to put in WebBrowser a background image and then make it transparent?

PS. it's Visual Studio 2010 Professional and .NET Framework 4 installed from the same file on both computers.


I updated my IE browser to version 8, and works perfect.

0

精彩评论

暂无评论...
验证码 换一张
取 消