zoukankan      html  css  js  c++  java
  • 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;
    
  • 相关阅读:
    python库--pandas--文本文件读取
    python库--flashtext--大规模数据清洗利器
    PyCharm--帮助文档
    Git--命令
    symfony doctrine generate entity repository
    [转]MySQL性能优化的最佳20+条经验
    svn使用
    一致性hash
    JavaScript学习笔记 1
    curl发出请求
  • 原文地址:https://www.cnblogs.com/igaoshang/p/GDIPlus.html
Copyright © 2011-2022 走看看