2014-07-24 33 views
0

我試圖在MFC對話框(C++)上顯示圖像。在MFC C++上圍繞圖像的不需要的框架

如果我顯示一個JPG,一切正常,但與透明區域PNG結果是不同的。

我使用的只是黑色和透明的png圖像,但它周圍還有一個白色的框架,以及其他一些區域。

這是代碼我使用:

CDC *pDC; 
pDC = this->GetDC(); 
HDC hdc = pDC->GetSafeHdc(); 
CImage image; 
image.Load(".//home.png"); 
image.Draw(hdc , 50, 50); 

這是結果:

enter image description here

任何想法?

順便說一句,我應該最終釋放pDC嗎?

回答

0

我發現了一個簡單的方法來做到這一點:

CDC *pDC; 
pDC = this->GetDC(); 
HDC hdc = pDC->GetSafeHdc(); 
Gdiplus::Graphics G(hdc); 
Gdiplus::Image I(L".//home.png"); 
G.DrawImage(&I,0,0); 
0

使用透明度需要使用「預先倍增」的圖像。從本質上講,通過圖像的像素運行(看GetBits())第一次使用前一次轉換每個像素由組件類似:

c[0] = (unsigned char)((unsigned int)c[0] * (unsigned int)c[3]/255); 
c[1] = (unsigned char)((unsigned int)c[1] * (unsigned int)c[3]/255); 
c[2] = (unsigned char)((unsigned int)c[2] * (unsigned int)c[3]/255); 

您可以搜索網上的一些例子。