• GDI与GDI+性能比较


    编写程序对GDI和GDI+绘制进行了比较,经过比较,GDI相对GDI+还是有一些性能优势的。

    同时比较了每次绘制创建TGPGraphics对象和共用一个TGPGraphics对象的情况,两者性能相差不大,几可忽略。

    1.用GDI绘制5K次----耗时约为19s200ms

    procedure TForm8.WMPaint(var Message: TWMPaint);
    var
      ps: PAINTSTRUCT;
      LClientRect: TGPRect;
      LGraph: TGPGraphics;
      LBrush: TGPBrush;
      LBr: HGDIOBJ;
    begin
      if m_nCount < 5000 then
      begin
        //创建缓存
        BeginPaint(Handle, ps);
        if not Assigned(m_memDC) then
          m_memDC := TMemoryDC.Create(ps.hdc);
        m_memDC.SetBounds(ps.hdc, Self.ClientRect);
    
        //用GDI+绘制
    //    LBrush := TGPSolidBrush.Create(aclRed);
    //    LClientRect := MakeRect(Self.ClientRect);
    //    m_memDC.Graph.FillRectangle(LBrush, LClientRect);
    //    LBrush.Free;
    
        //用GDI绘制
        LBr := CreateSolidBrush(clRed);
        FillRect(m_memDC.DC, Self.ClientRect, LBr);
        DeleteObject(LBr);
    
        //缓冲去拷贝
        m_memDC.Blt(ps.hdc);
        EndPaint(Handle, ps);
        Message.Result := 0;
        Inc(m_nCount);
      end
      else
      begin
        BeginPaint(Handle, ps);
        EndPaint(Handle, ps);
        Message.Result := 0;
      end;
    end;
    

    2.用GDI+绘制5K次----耗时约为19s600ms

    procedure TForm8.WMPaint(var Message: TWMPaint);
    var
      ps: PAINTSTRUCT;
      LClientRect: TGPRect;
      LGraph: TGPGraphics;
      LBrush: TGPBrush;
      LBr: HGDIOBJ;
    begin
      if m_nCount < 5000 then
      begin
        //创建缓存
        BeginPaint(Handle, ps);
        if not Assigned(m_memDC) then
          m_memDC := TMemoryDC.Create(ps.hdc);
        m_memDC.SetBounds(ps.hdc, Self.ClientRect);
    
        //用GDI+绘制
        LGraph := TGPGraphics.Create(m_memDC.DC);
        LBrush := TGPSolidBrush.Create(aclRed);
        LClientRect := MakeRect(Self.ClientRect);
        LGraph.FillRectangle(LBrush, LClientRect);
        LGraph.Free;
        LBrush.Free;
    
        //用GDI绘制
    //    LBr := CreateSolidBrush(clRed);
    //    FillRect(m_memDC.DC, Self.ClientRect, LBr);
    //    DeleteObject(LBr);
    
        //缓冲去拷贝
        m_memDC.Blt(ps.hdc);
        EndPaint(Handle, ps);
        Message.Result := 0;
        Inc(m_nCount);
      end
      else
      begin
        BeginPaint(Handle, ps);
        EndPaint(Handle, ps);
        Message.Result := 0;
      end;
    end;
    

    3.用GDI+绘制5K次(不重复创建TGPGraphics)----耗时约为19s500ms

    procedure TForm8.WMPaint(var Message: TWMPaint);
    var
      ps: PAINTSTRUCT;
      LClientRect: TGPRect;
      LGraph: TGPGraphics;
      LBrush: TGPBrush;
      LBr: HGDIOBJ;
    begin
      if m_nCount < 5000 then
      begin
        //创建缓存
        BeginPaint(Handle, ps);
        if not Assigned(m_memDC) then
          m_memDC := TMemoryDC.Create(ps.hdc);
        m_memDC.SetBounds(ps.hdc, Self.ClientRect);
    
        //用GDI+绘制
        LBrush := TGPSolidBrush.Create(aclRed);
        LClientRect := MakeRect(Self.ClientRect);
        m_memDC.Graph.FillRectangle(LBrush, LClientRect);
        LBrush.Free;
    
        //用GDI绘制
    //    LBr := CreateSolidBrush(clRed);
    //    FillRect(m_memDC.DC, Self.ClientRect, LBr);
    //    DeleteObject(LBr);
    
        //缓冲去拷贝
        m_memDC.Blt(ps.hdc);
        EndPaint(Handle, ps);
        Message.Result := 0;
        Inc(m_nCount);
      end
      else
      begin
        BeginPaint(Handle, ps);
        EndPaint(Handle, ps);
        Message.Result := 0;
      end;
    end;
    
  • 相关阅读:
    centos搭建window下写的flask程序
    【MTK】iwpriv命令说明
    vs2019专业版离线安装方法
    Python文件编译成exe
    python3升级与安装
    谷歌浏览器https和flash禁用的解决方法
    SQL注入常见函数
    nmap简介与运用
    WPF 万维网对战象棋 客户端+服务端(全套可执行代码在文章末尾)
    《软件工程实践》2020春季学期教学回顾--线上教学,化弊为利
  • 原文地址:https://www.cnblogs.com/igaoshang/p/GDIPlus.html
Copyright © 2020-2023  润新知