1 / 20

绘制图形和显示图片

绘制图形和显示图片. 主要内容. 屏幕绘图函数介绍 直接在屏幕上绘图 显示位图或 SVG 图 特殊效果绘图. 屏幕绘图函数. 绘制基本形状 API 设备绘图上下文类 CWindowGc 提供绘图 API void DrawArc(const TRect &aRect,const TPoint &aStart,const TPoint &aEnd); void DrawLine(const TPoint &aPoint1,const TPoint &aPoint2); void DrawLineTo(const TPoint &aPoint);

yovela
Download Presentation

绘制图形和显示图片

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 绘制图形和显示图片

  2. 主要内容 • 屏幕绘图函数介绍 • 直接在屏幕上绘图 • 显示位图或SVG图 • 特殊效果绘图

  3. 屏幕绘图函数 • 绘制基本形状API • 设备绘图上下文类CWindowGc 提供绘图API void DrawArc(const TRect &aRect,const TPoint &aStart,const TPoint &aEnd); void DrawLine(const TPoint &aPoint1,const TPoint &aPoint2); void DrawLineTo(const TPoint &aPoint); void DrawLineBy(const TPoint &aPoint); void DrawPolyLine(const CArrayFix<TPoint> *aPointList); void DrawPolyLine(const TPoint* aPointList,TInt aNumPoints); void DrawPie(const TRect &aRect,const TPoint &aStart,const TPoint &aEnd); void DrawEllipse(const TRect &aRect); void DrawRect(const TRect &aRect); void DrawRoundRect(const TRect &aRect,const TSize &aEllipse); ... ...

  4. 屏幕绘图函数 • 绘制图片API • 设备绘图上下文类CWindowGc 提供绘图API void BitBlt(const TPoint &aPos, const CFbsBitmap *aBitmap); void BitBlt(const TPoint &aDestination, const CFbsBitmap *aBitmap, const TRect &aSource); void BitBltMasked(const TPoint& aPoint,const CFbsBitmap* aBitmap, const TRect& aSourceRect,const CFbsBitmap* aMaskBitmap, TBool aInvertMask); void BitBlt(const TPoint &aPoint, const CWsBitmap *aBitmap); void BitBlt(const TPoint &aDestination, const CWsBitmap *aBitmap, const TRect &aSource); void BitBltMasked(const TPoint& aPoint,const CWsBitmap *aBitmap, const TRect& aSourceRect,const CWsBitmap *aMaskBitmap, TBool aInvertMask);

  5. 屏幕绘图函数 • 绘制图片API • 设备绘图上下文类CWindowGc 提供绘图API void DrawBitmap(const TPoint &aTopLeft, const CFbsBitmap *aDevice); void DrawBitmap(const TRect &aDestRect, const CFbsBitmap *aDevice); void DrawBitmap(const TRect &aDestRect, const CFbsBitmap *aDevice, const TRect &aSourceRect); void DrawBitmapMasked(const TRect& aDestRect, const CFbsBitmap* aBitmap, const TRect& aSourceRect, const CFbsBitmap* aMaskBitmap, TBool aInvertMask); void DrawBitmapMasked(const TRect& aDestRect, const CWsBitmap* aBitmap, const TRect& aSourceRect, const CWsBitmap* aMaskBitmap, TBool aInvertMask);

  6. 屏幕绘图函数 • 图片格式 • 位图或SVG图

  7. 直接在屏幕上绘图 void CGraphicExamContainer::Draw(const TRect& aRect) const { CWindowGc& gc = SystemGc(); //清空窗口上的内容 gc.SetPenStyle( CGraphicsContext::ENullPen ); gc.SetBrushColor( KRgbGray ); gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); gc.DrawRect( aRect ); //绘制图形 gc.SetPenStyle(CGraphicsContext::ESolidPen); gc.SetPenSize(TSize(3,3)); gc.SetPenColor(KRgbBlack); gc.DrawEllipse(aRect); }

  8. 显示位图或矢量图 • 打包图片 • 打包位图资源 • 在mmp文件中进行位图资源的打包 START BITMAP graphic_bmp.mbm HEADER TARGETPATH \system\apps\graphics SOURCEPATH ..\picture\bmp SOURCE c12 image1.bmp SOURCE c12 image2.bmp SOURCE 1 image2_mask.bmp END

  9. 显示位图或矢量图 • 打包图片 • 打包SVG图资源 • 在*.mk文件中进行SVG图资源的打包 ifeq (WINS,$(findstring WINS, $(PLATFORM))) ZDIR=$(EPOCROOT)epoc32\release\$(PLATFORM)\$(CFG)\Z else ZDIR=$(EPOCROOT)epoc32\data\z endif TARGETDIR=$(ZDIR)\RESOURCE\APPS HEADERDIR=$(EPOCROOT)epoc32\include ICONTARGETFILENAME=$(TARGETDIR)\graphic_svg.mif HEADERFILENAME=$(HEADERDIR)\graphic_svg.mbg … … RESOURCE : mifconv $(ICONTARGETFILENAME) /h$(HEADERFILENAME) \ /c8,1 ..\picture\svg\sound.svg

  10. 显示位图或矢量图 • 图片加载 • 加载位图 CFbsBitmap* iBackgroundImage; //加载位图 _LIT(KBitmapPath, "\\resource\\apps\\graphic_bmp.mbm"); TFileName bitmapFile (KBitmapPath); User::LeaveIfError (CompleteWithAppPath (bitmapFile)); iBackgroundImage = iEikonEnv->CreateBitmapL( bitmapFile,EMbmGraphic_bmpImage1 );

  11. 显示位图或矢量图 • 图片加载 • 加载SVG图 CFbsBitmap* iSoundSvg; //加载svg矢量图 _LIT(KSvgPath, "\\resource\\apps\\graphic_svg.mif"); TFileName svgFile (KSvgPath); User::LeaveIfError (CompleteWithAppPath (svgFile)); AknIconUtils::CreateIconL(iSoundSvg, iSoundSvgMask, svgFile, EMbmGraphic_svgSound,EMbmGraphic_svgSound_mask); //iSoundSvg=AknIconUtils::CreateIconL(svgFile,EMbmGraphic_svgSound); AknIconUtils::SetSize(iSoundSvg, TSize(50,50), EAspectRatioNotPreserved); AknIconUtils::SetSize(iSoundSvgMask, TSize(50,50), EAspectRatioNotPreserved);

  12. 显示位图或SVG图 • 直接显示图片 //绘制客户区背景 //gc.BitBlt( Rect().iTl,iBackgroundImage ); gc.DrawBitmap(aRect,iBackgroundImage);

  13. 显示位图或SVG图 • 透明显示图片 //绘制透明位图 TSize size=iImage2->SizeInPixels(); TRect sourceRect( TPoint( 0,0 ),size); ptPos.iX+=size.iWidth; gc.BitBltMasked(ptPos,iImage2,sourceRect,iImage2mask,ETrue); //绘制透明SVG图 TSize size2=iSoundSvg->SizeInPixels(); TRect sourceRect2( TPoint( 0,0 ),size2); ptPos.iX+=size2.iWidth; gc.BitBltMasked(ptPos,iSoundSvg,sourceRect2,iSoundSvgMask,ETrue);

  14. 特殊效果绘图 • 无闪烁重绘 • 离屏绘图

  15. 特殊效果绘图 • 无闪烁重绘 CFbsBitmap* iOffScreenBitmap; CFbsBitmapDevice* iOffScreenBitmapDevice; CFbsBitGc* iOffScreenBitmapGc; // 创建离屏位图、位图设备、位图设备上下文 iOffScreenBitmap = new ( ELeave ) CFbsBitmap(); CleanupStack::PushL( iOffScreenBitmap ); User::LeaveIfError( iOffScreenBitmap->Create( Rect().Size(),EColor4K ) ); CleanupStack::Pop(); iOffScreenBitmapDevice = CFbsBitmapDevice::NewL(iOffScreenBitmap ); iOffScreenBitmapDevice->CreateContext( iOffScreenBitmapGc );

  16. 特殊效果绘图 • 无闪烁重绘 //清除位图设备下文中的背景 iOffScreenBitmapGc->SetPenStyle( CGraphicsContext::ENullPen ); iOffScreenBitmapGc->SetBrushColor( KRgbGray ); iOffScreenBitmapGc->SetBrushStyle( CGraphicsContext::ESolidBrush ); iOffScreenBitmapGc->DrawRect( aRect ); iOffScreenBitmapGc->SetPenStyle(CGraphicsContext::ESolidPen); iOffScreenBitmapGc->DrawEllipse(Rect()); //复制位图中已经绘制好的图形到程序窗口客户区中 CWindowGc& gc = SystemGc(); gc.BitBlt( Rect().iTl,iOffScreenBitmap );

  17. 特殊效果绘图 • 放大或缩小图片 • 直接使用绘图API进行绘制 //绘制放缩的透明位图 ptPos.iX+=size.iWidth; size.iWidth*=2; size.iHeight*=2; TRect destRect(ptPos,size); gc.DrawBitmapMasked(destRect,iImage2,sourceRect,iImage2mask,ETrue);

  18. 特殊效果绘图 • 放大或缩小图片 • 对SVG图的直接缩放 //加载svg矢量图 _LIT(KSvgPath, "\\resource\\apps\\graphic_svg.mif"); TFileName svgFile (KSvgPath); User::LeaveIfError (CompleteWithAppPath (svgFile)); AknIconUtils::CreateIconL(iSoundSvg, iSoundSvgMask, svgFile, EMbmGraphic_svgSound,EMbmGraphic_svgSound_mask); //iSoundSvg=AknIconUtils::CreateIconL(svgFile,EMbmGraphic_svgSound); AknIconUtils::SetSize(iSoundSvg, TSize(50,50), EAspectRatioNotPreserved); AknIconUtils::SetSize(iSoundSvgMask, TSize(50,50), EAspectRatioNotPreserved);

  19. 特殊效果绘图 • 放大或缩小图片 • 使用位图转换工具类CMdaBitmapScaler进行缩放 void ScaleL(MMdaImageUtilObserver& aObserver,CFbsBitmap& aSrcBitmap, CFbsBitmap& aTgtBitmap,TBool aMaintainAspectRatio = ETrue); void ScaleL(MMdaImageUtilObserver& aObserver,CFbsBitmap& aBitmap, TSize aDestSize,TBool aMaintainAspectRatio = ETrue); void CancelScaling();

  20. 特殊效果绘图 • 旋转图像 • 转换工具类CMdaBitmapRotator • IMPORT_C void RotateL(MMdaImageUtilObserver& aObserver,CFbsBitmap& aSrcBitmap,CFbsBitmap& aTgtBitmap, TRotationAngle aAngle); • IMPORT_C void RotateL(MMdaImageUtilObserver& aObserver,CFbsBitmap& aBitmap,TRotationAngle aAngle);

More Related