void CChildView::OnFileOpenimage(void)
{
CString strFilter;
CSimpleArray<guid> aguidFileTypes;
HRESULT hResult;
hResult = imgOriginal.GetExporterFilterString(strFilter,aguidFileTypes);
if (FAILED(hResult)) {
CString fmt;
fmt.Format("GetExporterFilter failed:\n%x - %s", hResult, _com_error(hResult).ErrorMessage());
::AfxMessageBox(fmt);
return;
}
void CChildView::OnPaint()
{
CPaintDC dc(this); if (!imgOriginal.IsNull())
{
switch (m_nImageSize)
{
case SIZE_HALF:
imgOriginal.StretchBlt(dc,0,0,imgOriginal.GetWidth()/2,imgOriginal.GetHeight()/2,SRCCOPY);
break;
case SIZE_ORIGINAL:
imgOriginal.StretchBlt(dc,0,0,imgOriginal.GetWidth(),imgOriginal.GetHeight(),SRCCOPY);
break;
case SIZE_DOUBLE:
imgOriginal.StretchBlt(dc,0,0,imgOriginal.GetWidth()*2,imgOriginal.GetHeight()*2,SRCCOPY);
break;
case SIZE_FILL:
CRect rctWindowSize;
GetClientRect(rctWindowSize);
imgOriginal.StretchBlt(dc,0,0,rctWindowSize.Width(),rctWindowSize.Height(),SRCCOPY);
};
}
}
From atlimage.h
void SetHasAlphaChannel( bool bHasAlphaChannel ) throw();
LONG SetTransparentColor( LONG iTransparentColor ) throw();
COLORREF SetTransparentColor( COLORREF clrTransparentColor ) throw();
BOOL TransparentBlt( HDC hDestDC, int xDest, int yDest, int nDestWidth,
int nDestHeight, UINT crTransparent = CLR_INVALID ) const throw();
BOOL TransparentBlt( HDC hDestDC, const RECT& rectDest,
UINT crTransparent = CLR_INVALID ) const throw();
BOOL TransparentBlt( HDC hDestDC, int xDest, int yDest, int nDestWidth,
int nDestHeight, int xSrc, int ySrc, int nSrcWidth, int nSrcHeight,
UINT crTransparent = CLR_INVALID ) const throw();
BOOL TransparentBlt( HDC hDestDC, const RECT& rectDest, const RECT& rectSrc,
UINT crTransparent = CLR_INVALID ) const throw();
COLORREF GetTransparentRGB() const;
inline BOOL CImage::TransparentBlt( HDC hDestDC, int xDest, int yDest,
int nDestWidth, int nDestHeight, int xSrc, int ySrc, int nSrcWidth,
int nSrcHeight, UINT crTransparent ) const throw()
{
BOOL bResult;
ATLASSUME( m_hBitmap != NULL );
ATLENSURE_RETURN_VAL( hDestDC != NULL, FALSE );
GetDC();
if( crTransparent == CLR_INVALID )
{
crTransparent = GetTransparentRGB();
}
bResult = ::TransparentBlt( hDestDC, xDest, yDest, nDestWidth, nDestHeight,
m_hDC, xSrc, ySrc, nSrcWidth, nSrcHeight, crTransparent );
ReleaseDC();
return( bResult );
}
</guid>
It is never as straight forward as one might hope. Before you TransparentBlt you need to set the color that isgoing to be transparent. This is the code that you are trying to use.
Hope this helpd.