转自:http://www.devdiv.net/thread-10592-1-2.html
void CMegajoyContainer::ConvertToAlpha(CWindowGc& gc,CFbsBitmap *imgToBrighten) const
{
CFbsBitmap* iEmptyBitmap = new ( ELeave ) CFbsBitmap();
CleanupStack::PushL( iEmptyBitmap );
User::LeaveIfError( iEmptyBitmap->Create( imgToBrighten->SizeInPixels(), CEikonEnv::Static()->DefaultDisplayMode() ) );
CFbsBitmapDevice *iGD = CFbsBitmapDevice::NewL( iEmptyBitmap );
CleanupStack::PushL( iGD );
CFbsBitGc *iGC;
User::LeaveIfError( iGD->CreateContext( iGC ) );
iGC->SetPenStyle( CGraphicsContext::ENullPen );
iGC->SetBrushColor( KRgbWhite );
iGC->SetBrushStyle( CGraphicsContext::ESolidBrush );
iGC->DrawRect( TRect(TPoint(0,0), iEmptyBitmap->SizeInPixels()) );
iGC->SetBrushStyle( CGraphicsContext::ENullBrush );
delete iGC;
CleanupStack::PopAndDestroy( iGD );
CFbsBitmap* iEmptyBitmapMask = new ( ELeave ) CFbsBitmap();
CleanupStack::PushL( iEmptyBitmapMask );
User::LeaveIfError( iEmptyBitmapMask->Create( imgToBrighten->SizeInPixels(), EGray256 ) );
iGD = CFbsBitmapDevice::NewL( iEmptyBitmapMask );
CleanupStack::PushL( iGD );
User::LeaveIfError( iGD->CreateContext( iGC ) );
iGC->SetPenStyle( CGraphicsContext::ENullPen );
iGC->SetBrushColor( KRgbGray );
iGC->SetBrushStyle( CGraphicsContext::ESolidBrush );
iGC->DrawRect( TRect(TPoint(0,0), iEmptyBitmap->SizeInPixels()) );
iGC->SetBrushStyle( CGraphicsContext::ENullBrush );
delete iGC;
CleanupStack::PopAndDestroy( iGD );
gc.BitBltMasked(TPoint(0,0),iEmptyBitmap,TRect(TPoint(0,0),iEmptyBitmapMask->SizeInPixels()),iEmptyBitmapMask,EFalse);
CleanupStack::PopAndDestroy(iEmptyBitmapMask);
CleanupStack::PopAndDestroy( iEmptyBitmap );
}
注意要在.mmp文件中加入库文件
LIBRARY bitgdi.lib
LIBRARY ws32.lib
LIBRARY fbscli.lib
阅读(437) | 评论(0) | 转发(0) |