gdiplus绘制带透明通道文本

本文通过使用GDI+库,对比了多种文本渲染效果,包括ClearType、AntiAlias等,并展示了如何将渲染后的文本绘制到包含透明通道的位图上。
  1. [list]
  2. [*]Private Sub Form_Load()
  3. [*]    InitGDIPlus
  4. [*]   
  5. [*]    Dim memBmp As Long, memGraphics As Long
  6. [*]    CreateBitmapWithGraphics memBmp, memGraphics, 200, 100, PixelFormat32bppARGB
  7. [*]   
  8. [*]    Dim gFontFamily As Long, gFont As Long, gStrFmt As Long
  9. [*]    GdipCreateFontFamilyFromName StrPtr("微软雅黑"), 0, gFontFamily
  10. [*]    GdipCreateFont gFontFamily, 13, FontStyle.FontStyleRegular, UnitPixel, gFont
  11. [*]    GdipCreateStringFormat 0, 0, gStrFmt
  12. [*]    GdipSetStringFormatAlign gStrFmt, StringAlignmentNear
  13. [*]   
  14. [*]    Dim rc As RECTF
  15. [*]    Dim Brush As Long
  16. [*]    GdipCreateSolidFill &HFF0000FF, Brush
  17. [*]   
  18. [*]    '先测试ClearType
  19. [*]    GdipSetTextRenderingHint memGraphics, TextRenderingHintClearTypeGridFit
  20. [*]    GdipDrawString memGraphics, StrPtr("ClearType 文字"), -1, gFont, rc, gStrFmt, Brush
  21. [*]   
  22. [*]    rc.Top = 20
  23. [*]    '测试AntiAlias GridFit
  24. [*]    GdipSetTextRenderingHint memGraphics, TextRenderingHintAntiAliasGridFit
  25. [*]    GdipDrawString memGraphics, StrPtr("AntiAlias GridFit 文字"), -1, gFont, rc, gStrFmt, Brush
  26. [*]   
  27. [*]    rc.Top = 40
  28. [*]    '测试AntiAlias
  29. [*]    GdipSetTextRenderingHint memGraphics, TextRenderingHintAntiAlias
  30. [*]    GdipDrawString memGraphics, StrPtr("AntiAlias 文字"), -1, gFont, rc, gStrFmt, Brush
  31. [*]
  32. [*]    rc.Top = 60
  33. [*]    '测试SingleBitPerPixel GridFit
  34. [*]    GdipSetTextRenderingHint memGraphics, TextRenderingHintSingleBitPerPixelGridFit
  35. [*]    GdipDrawString memGraphics, StrPtr("SingleBitPerPixel GridFit 文字"), -1, gFont, rc, gStrFmt, Brush
  36. [*]
  37. [*]    rc.Top = 80
  38. [*]    '测试SingleBitPerPixel
  39. [*]    GdipSetTextRenderingHint memGraphics, TextRenderingHintSingleBitPerPixel
  40. [*]    GdipDrawString memGraphics, StrPtr("SingleBitPerPixel 文字"), -1, gFont, rc, gStrFmt, Brush
  41. [*]   
  42. [*]    Dim frmGraphics As Long
  43. [*]    GdipCreateFromHDC hDC, frmGraphics
  44. [*]    GdipGraphicsClear frmGraphics, &HFFFFFFFF
  45. [*]   
  46. [*]    GdipSetTextRenderingHint frmGraphics, TextRenderingHintClearTypeGridFit
  47. [*]    rc.Top = 10
  48. [*]    rc.Left = 10
  49. [*]    GdipDeleteBrush Brush
  50. [*]    GdipCreateSolidFill &HFF000000, Brush
  51. [*]    GdipDrawString frmGraphics, StrPtr("绘制到包含透明通道的位图:"), -1, gFont, rc, gStrFmt, Brush
  52. [*]   
  53. [*]    GdipDrawImageRectI frmGraphics, memBmp, 10, 40, 200, 100
  54. [*]   
  55. [*]    GdipDeleteBrush Brush
  56. [*]    GdipDeleteStringFormat gStrFmt
  57. [*]    GdipDeleteFont gFont
  58. [*]    GdipDeleteFontFamily gFontFamily
  59. [*]    GdipDeleteGraphics frmGraphics
  60. [*]    GdipDeleteGraphics memGraphics
  61. [*]    GdipDisposeImage memBmp
  62. [*]   
  63. [*]    TerminateGDIPlus
  64. [*]End Sub
  65. [*]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值