Symbian 的CFbsBitmap类并没有提供缩放的API,在实际应用中,很可能对CFbsBitmap对象进行缩放。郁闷了半天
在网上收缩到一段代码,感谢某某高人。
CFbsBitmap* XXX::ResizeBitmap(CFbsBitmap* aSourceBitmap,TInt aWidth,TInt aHeight)
{
if(!aSourceBitmap ){
return NULL;
} // 创建一张新的位图
CFbsBitmap* aDestBitmap = new (ELeave) CFbsBitmap;
CleanupStack::PushL(aDestBitmap);
User::LeaveIfError(aDestBitmap->Create(TSize(aWidth,aHeight),aSourceBitmap->DisplayMode()));
TInt iSourceWidth = aSourceBitmap->SizeInPixels().iWidth;
TInt iSourceHeight = aSourceBitmap->SizeInPixels().iHeight;
TInt iDestWidth = aDestBitmap->SizeInPixels().iWidth;
TInt iDestHeight = aDestBitmap->SizeInPixels().iHeight;
if(iSourceWidth==0 || iSourceHeight==0 || iDestHeight==0 || iDestWidth==0)
{
CleanupStack::PopAndDestroy();
return NULL;
}
// 用TBitmapUtil来对位图进行加锁
TBitmapUtil iSourceUtil(aSourceBitmap);
TBitmapUtil iDestUtil(aDestBitmap);
iSourceUtil.Begin(TPoint(0,0));
iDestUtil.Begin(TPoint(0,0),iSourceUtil);
// 按照缩放比例写入像素点
for(TInt w = 0 ; w < iDestWidth ; ++ w){
for(TInt h = 0 ; h < iDestHeight ; ++ h){
iDestUtil.SetPos(TPoint(w,h));
iSourceUtil.SetPos(TPoint(w*iSourceWidth/iDestWidth,h*iSourceHeight/iDestHeight));
iDestUtil.SetPixel(iSourceUtil.GetPixel());
}
}
iDestUtil.End();
iSourceUtil.End();
CleanupStack::Pop(aDestBitmap);
return aDestBitmap;
}