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.

为何MAknsSkinInstance::GetCachedItemData()返回NULL?

From Wiki
Jump to: navigation, search

Archived.png存档: 这篇文章是存档,因为考虑到今天它与第三方开发者建立商业解决方案不相关。

Article Metadata

兼容于
平台: S60 3rd Edition (initial release) and FP1
S60 3rd Edition FP1
S60 3rd Edition (initial release)

文章
翻译:
huwell
最后由 hamishwillee 在 27 Sep 2012 编辑
  • 详细描述

S60中的skin server提供了一种方法从默认皮肤元素中创建一张位图(CFbsBitmap)。

位图通常从皮肤中获取,如下所示:

#include <aknsskininstance.h> 
 
MAknsSkinInstance* skin = AknsUtils::SkinInstance();
 
CAknsItemData* skinItem = skin->GetCachedItemData( someUID, EAknsITBitmap );
if( skinItem != NULL )
{
CFbsBitmap* bitmap = static_cast<CAknsBitmapItemData*>(skinItem)->Bitmap();
}


上述方法对位图(EAknsITBitmaps)或遮罩位图(EAknsITMaskedBitmap)来说都工作得很好,但这并不意味着对所有皮肤元素都如此。例如,如果上面的someUID出现下列值时:

KAknsIIDQsnBgAreaMainIdle, 
KAknsIIDQsnBgScreenIdle,
KAknsIIDQsnBgScreen

那么GetCachedItemData()则会返回NULL,因为这些UID不是和位图挂钩的,他们只是EAknsITEffectQueue类型的一部分。


如果当前主题中的某个皮肤元素是EAknsITEffectQueue类型。这就意味这该元素是支持特效的。特效是scalable UI的主要特性之一。当一个皮肤元素支持特效,这就意味着该元素有多个帧。每帧都可能是一个图片或是图片/像素处理方案(能对前一帧产生影响)。特效可以通过改变时间来编程处理,甚至能将另一个皮肤元素指名为第一张图片(背景图)。

正因为如此,我们无法通过MAknsSkinInstance从EAknsITEffectQueue类型的皮肤元素中返回一个单独的CFbsBitmap实例,下列解决方案描述了如何处理这样的情况。


  • 解决方案

使用AknsDrawUtils来处理:


1)如果程序需要在它的一个控件(从CCoeControl派生)中绘制一个当前背景皮肤,就可以使用AknsDrawUtils::Background()来处理:

下列代码演示了如何处理:

// Create a background context (in ConstructL(), as a class member)
iSkinContext = CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain, Rect(), EFalse );

Then, in the Draw() function:

CWindowGc& gc = SystemGc();
TRect rect = Rect();
gc.Clear( rect );
AknsDrawUtils::Background( AknsUtils::SkinInstance(), iSkinContext, this, gc, rect );


2)如果程序需要一个位图实例,就可以利用AknsDrawUtils::DrawBackground()在一个CFbsBitGc上绘制出当前皮肤内容:

// Create an off-screen bitmap and context (CFbsBitGc)
// Also remember to take care of destruction / cleanup during leaves
 
CFbsBitmap* offScreenBitmap = new (ELeave) CFbsBitmap();
User::LeaveIfError( offScreenBitmap->Create( aSize, aDisplayMode ) );
CFbsBitGc* bitGc = 0;
CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL( offScreenBitmap );
User::LeaveIfError( bitmapDevice->CreateContext( bitGc ) );
 
// Draw the content on the off-screen bitmap
AknsDrawUtils::DrawBackground( AknsUtils::SkinInstance(), iSkinContext, this, *bitGc, TPoint(0,0), rect, KAknsDrawParamDefault );
 
// offScreenBitmap now contains current skin content
This page was last modified on 27 September 2012, at 06:16.
354 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.

×