1

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, 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.

alcohol is evil
  • 686
  • 12
  • 34
  • Isn't transparent png support on win xp a bit wobbly? – CodingBarfield Aug 29 '11 at 07:25
  • you're right CodingBarfield! I opened that site in chrome and IE http://www.silisoftware.com/png_alpha_transparency/ . Png looks very bad on IE on XP (its version is 6). That's why win7 is ok, because it's got newer version of IE. – alcohol is evil Aug 30 '11 at 10:55
  • Any ideas how to attach newer that IE6 module to my program, so it can look good on any PC (no matter which version of IE the user has got)? Answer and I'll set it as best answer. – alcohol is evil Aug 30 '11 at 10:58

1 Answers1

0

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

alcohol is evil
  • 686
  • 12
  • 34