I use the CImage class to load PNG file and do the alpha blending in a
dialog's OnPaint:
CImage m_imgTest;//in the header file
m_imgTest.Load(_T("test.png"));//in OnInitDialog
//In OnPaint:
CPaintDC dc(this);
m_imgBack.BitBlt((HDC)dc,0,0);//an other image as background
if(!m_imgTest.IsNull())
m_imgTest.AlphaBlend((HDC)dc,5,164);
Somehow the alpha blendig works - I can see the background throug some
parts of my test.png and completely transparent parts of test.png
ain't visible at all.
But there must be something wrong with the alpha function or the alpha
data: parts with a very low alpha are displayed as if they had a high
alpha.
I put the same pictures as back- and foreground into an html file and
started it in IExplore & FireFox. Both programs deliver alpha blending
as expected.
What am I doing wrong?
Best Regards & thanks in advance,
Thomas
I overwrote CImage::Load() and now everything works fine:
HRESULT CImg::Load(LPCTSTR pszFileName, bool bPreMultiply)
{
HRESULT retRes = CImage::Load(pszFileName);
if(!IsNull() && bPreMultiply)
{
unsigned char * pCol = 0;
long lW = GetWidth();
long lH = GetHeight();
for(long ixy = 0; ixy < lH; ixy ++)
{
for(long ixx = 0; ixx < lW; ixx ++)
{
pCol = (unsigned char *)GetPixelAddress(ixx,ixy);
unsigned char alpha = pCol[3];
if(alpha < 255)
{
pCol[0] = ((pCol[0] * alpha) + 127) / 255;
pCol[1] = ((pCol[1] * alpha) + 127) / 255;
pCol[2] = ((pCol[2] * alpha) + 127) / 255;
}
}
}
}
return retRes;
}