图片半透明效果

我封装了一个方法,传入相应的图片,就会把图片变成半透明效果并显示在程序界面上.

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

效果如下:

原图片为

转变后的图片为

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值