views:

113

answers:

1

I'm displaying a PNG with a transparent background that looks good in Windows 7, but then I run my app in XP Mode or remote desktop to a Windows XP machine and the PNG looks incorrect. I noticed that if I disable "Integration Mode" or run the app on XP without remote desktop, the image looks fine.

How do I get DrawImage to render the PNG correctly in XP Mode or remote desktop?

Image inside Windows 7

alt text

Image inside XP Mode or remote desktop

alt text

Here's my code:

protected override void OnPaint(PaintEventArgs e)
{
    Image image = Image.FromFile("hello.png", false);
    Bitmap bmp = new Bitmap(image);

    Rectangle destRect = new Rectangle(0, 0, image.Width, image.Height);

    e.Graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
    base.OnPaint(e);
}
+2  A: 

Remote Desktop by default runs with 16 bit color, which I believe is incompatible with alpha blending. You need to reconfigure the display for 32 bit mode, if that's possible.

Mark Ransom
If I load and display the same image using a PictureBox control, it looks fine in XP Mode even though my DrawImage doesn't. So it seems like there must be a way to get DrawImage to render correctly despite it being 16-bit.
simplecoder
@simplecoder, using a PictureBox control converts the transparency to the background of the control and eliminates the alpha blending that needs to occur.
Mark Ransom