Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

在缩放图片时不保留高宽比将导致程序异常

From Wiki
Jump to: navigation, search
Article Metadata

测试基于
设备:: N70, N90

兼容于
平台: S60 2nd Edition FP3

文章
关键词: CBitmapScaler
huwell 在 28 Jun 2007 创建
最后由 hamishwillee 在 30 May 2013 编辑
  • 设备, 软件 版本: S60 2nd Edition, FP3, N70, N90
  • 说明:如果在使用CBitmapScaler::Scale()时将aMaintainAspectRatio参数设置为EFalse,将会导致程序异常
  • 详细描述:如果程序使用CBitmapScaler的Scale方法将一个张图片(如为132x176)进行了缩放处理(如176x144),而其aMaintainAspectRatio参数为EFalse,则程序会引发USER 21错误,异常中断。
  • 解决方案:如果需要将上述情况进行缩放绘制到屏幕上,你可以使用CGraphicContext:DrawBitmap方法。

如果缩放后的图片还要使用,你可在CBitmapContext对象上使用同样方式处理,保持图片原来构造时的样子。下列代码可融入Series 60 Developer Platform 2.0: Image Converter Example示例中做测试使用。

void CImageConverterEngine::ScaleL(TSize aSize)
{
CWsBitmap *newBitmap = new (ELeave)
CWsBitmap(CEikonEnv::Static()->WsSession());
CleanupStack::PushL(newBitmap);
User::LeaveIfError(newBitmap->Create(
aSize,CEikonEnv::Static()->DefaultDisplayMode()));
CFbsBitmapDevice* bitDev = CFbsBitmapDevice::NewL(newBitmap);
CleanupStack::PushL(bitDev);
CBitmapContext* bgc = NULL;
User::LeaveIfError(bitDev->CreateBitmapContext(bgc));
bgc->DrawBitmap(TRect(TPoint(0,0), aSize), iBitmap);
delete bgc;
CleanupStack::PopAndDestroy(2); // bitDev, newBitmap
delete iBitmap;
iBitmap = newBitmap;
iController->NotifyCompletion(KErrNone);
}
This page was last modified on 30 May 2013, at 04:41.
35 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×