加载PNG时的CImageDecoder和AO

加载png时创建CImageDecoder和AO的具体过程(下面的方法在decode的同时还根据png的alpha生成了mask做透明操作,但是不支持半透明alpha混合…):


在symbiandev.com.cn上看到的这段:
    [color=#008000]// create the decoder[/color]
    iImageDecoder = CImageDecoder::FileNewL( iFs, aFileName, CImageDecoder::EAllowGeneratedMask);
    TFrameInfo frameInfo = iImageDecoder->FrameInfo();
    
    [color=#008000]// create the destination bitmap[/color]
    iBitmap = [color=#0000D0]new[/color] (ELeave) CFbsBitmap();
    iBitmap->Create( iImageDecoder->FrameInfo().iOverallSizeInPixels,
                    iImageDecoder->FrameInfo().iFrameDisplayMode ); 
    
    iBitmask = [color=#0000D0]new[/color] (ELeave) CFbsBitmap();
    TInt r = iBitmask->Create(iImageDecoder->FrameInfo().iOverallSizeInPixels, EGray256);
    [color=#0000D0]if[/color] (KErrNone == r) {
       [color=#008000]// start conversion to bitmap[/color]
       iState = EDecoding;
       iImageDecoder->Convert( &iStatus, *iBitmap, *iBitmask );
       SetActive();
    }
    。。。。。。。。。。。
  gc.BitBltMasked(TPoint(0,0), iBitmap, iBitmask->SizeInPixels(), iBitmask, ETrue);
其中iState还有下面的SetActive都是配合AO(ActiveObject)的,类似多线程的概念,大概看了一下AO,貌似要继承一个CActive,然后还要实现一堆东西,看着挺麻烦,仔细研究了一下SDK,并参考了一些其他CImageDecoder的相关代码,发现,下面这样也是可以的:
[color=#008000]// 下面的decoder是要配合AO的[/color]
    [color=#008000]// 论坛上看到的例子是本类继承AO,可是我这样直接EOptionAlwaysThread貌似也是正确的[/color]
    RFs [color=#FF0000]fs[/color] = CEikonEnv::Static()->FsSession();
    TFileName aShip(CDodgeMasterContainer::instance->iPrivatePath);
    aShip.Append(aFileName);
    CImageDecoder
            *iImageDecoder = CImageDecoder::FileNewL(
                    [color=#FF0000]fs[/color],
                    aShip,
                    (CImageDecoder::TOptions)(CImageDecoder::EAllowGeneratedMask|CImageDecoder::EOptionAlwaysThread));
    TFrameInfo frameInfo = iImageDecoder->FrameInfo();
    [color=#008000]// 保存整张图片的大小[/color]
    iImgWidth = frameInfo.iOverallSizeInPixels.iWidth;
    iImgHeight = frameInfo.iOverallSizeInPixels.iHeight;
    [color=#008000]// create the destination bitmap[/color]
    iBitmap = [color=#0000D0]new[/color] (ELeave) CFbsBitmap();
    iBitmap->Create( iImageDecoder->FrameInfo().iOverallSizeInPixels, iImageDecoder->FrameInfo().iFrameDisplayMode);
    iBitmask = [color=#0000D0]new[/color] (ELeave) CFbsBitmap();
    TInt r = iBitmask->Create(iImageDecoder->FrameInfo().iOverallSizeInPixels, EGray256);
    [color=#0000D0]if[/color] (KErrNone == r)
    {
        [color=#008000]// start conversion to bitmap[/color]
        TRequestStatus iStatus;
        iImageDecoder->Convert( &iStatus, *iBitmap, *iBitmask);
        User::WaitForRequest(iStatus);
        [color=#008000]// SetActive();[/color]
    }
    [color=#0000D0]delete[/color] iImageDecoder;

博主友情提示:

如您在评论中需要提及如QQ号、电子邮件地址或其他隐私敏感信息,欢迎使用>>博主专用加密工具v3<<处理后发布,原文只有博主可以看到。