tags:

views:

367

answers:

1

I am trying to draw a transparent (alpha) PNG image using CxImage, but it seems I'm missing some obvious step... The code so far is:

CxImage image(m_pImage, m_lSize, CXIMAGE_FORMAT_UNKNOWN);

CRect rcOut = rc;
rcOut.left = (rc.Width()/2) - (image.GetWidth()/2);
rcOut.right = rcOut.left + image.GetWidth();
rcOut.top = (rc.Height()/2) - (image.GetHeight()/2);
rcOut.bottom = rcOut.top + image.GetHeight();

image.Draw(dc.GetSafeHdc(),rcOut);

where m_pImage is loaded elsewhere using:

CxImage image(strPath,CXIMAGE_FORMAT_UNKNOWN);
long lSize = 0;
BYTE * pBuf = NULL;

RGBQUAD rgbq;
rgbq.rgbRed = 255;
rgbq.rgbGreen = 255;
rgbq.rgbBlue = 255;
rgbq.rgbReserved = 0;

image.Thumbnail(paramImageSize, paramImageSize, rgbq);
image.SetJpegQuality(100);
image.Encode(pBuf, lSize, CXIMAGE_FORMAT_JPG);

Can you see what I'm missing?

Thanks in advance!

A: 

It seems that the Thumbnail() function caused those problem along with the destination format being JPEG. Changed to Resample2() and PNG and it's ok.

dennisV