2010-04-20 32 views
1

我顯示一個透明的背景,在Windows 7中看起來不錯,但後來我運行我的應用程序在XP模式或遠程桌面到Windows XP機器和PNG看起來不正確。我注意到,如果我禁用「集成模式」或在沒有遠程桌面的情況下在XP上運行應用程序,圖像看起來很好。在XP模式或遠程桌面DrawImage

如何讓DrawImage在XP模式或遠程桌面中正確呈現PNG?

圖片裏面的Windows 7

alt text http://www.freeimagehosting.net/uploads/957bb6ea8b.png

圖像XP模式內或遠程桌面

alt text http://www.freeimagehosting.net/uploads/08f1fbec46.png

這裏是我的代碼:

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

用默認運行遠程桌面16位顏色,我認爲這與alpha混合不兼容。如果可能的話,你需要重新配置32位顯示模式。

+0

如果我使用PictureBox控件加載並顯示相同的圖像,它在XP模式下看起來很好,即使我的DrawImage沒有。所以看起來好像有一種方法可以讓DrawImage正確呈現,儘管它是16位的。 – simplecoder 2010-04-20 21:04:56

+1

@simplecoder,使用PictureBox控件將透明度轉換爲控件背景,並消除需要發生的alpha混合。 – 2010-04-20 21:32:31