• Delphi中使用GDI+进行绘图(2)


    2)使用IGDIPlus接口

    (1)下载安装所需软件

    可以在以下地址下载IGDI+最新的安装程序。

    http://www.mitov.com/products/igdi+

    www.igdiplus.org

    打开压缩包:

    image

    其中有三个文件是我们需要的:

    IGDIPlus.pas

    IGDIPlusAPI.inc

    VCL.IGDIPlusExt.pas

    (2)使用IGDI+绘图

    将这三个文件加入到工程文件当中,或者设置包含目录,使工程能够找到上述文件。

    工程文件如下:

    image

    窗口文件如下:

    Pascal Code
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
      object GDIPlusDemoForm2: TGDIPlusDemoForm2
      Left = 0 
      Top = 0 
      Caption = 'GDIPlusDemo2' 
      ClientHeight = 289 
      ClientWidth = 554 
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11 
      Font.Name = 'Tahoma' 
      Font.Style = []
      OldCreateOrder = False 
      PixelsPerInch = 96 
      TextHeight = 13 
      object pb1: TPaintBox
        Left = 24 
        Top = 16 
        Width = 473 
        Height = 209 
        OnPaint = pb1Paint
      end 
    end

    代码如下:

    Pascal Code
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
      unit GDIPlusDemo2;

    interface 

    uses 
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
      System.Classes, Vcl.Graphics,Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
      Vcl.ExtCtrls, IGDIPlus, VCL.IGDIPlusExt;

    type 
      TGDIPlusDemoForm2 = class(TForm)
        pb1: TPaintBox;
        procedure pb1Paint(Sender: TObject);
      private 
        { Private declarations } 
      public 
        { Public declarations } 
      end;

    var 
      GDIPlusDemoForm2: TGDIPlusDemoForm2;

    implementation 

    {$R *.dfm} 

    procedure TGDIPlusDemoForm2.pb1Paint(Sender: TObject);
    var 
       g: IGPGraphics;
       p: IGPPen;
       b: IGPBrush;
       r: TIGPRect;
     begin 
       g := TIGPGraphics.FromCanvas(pb1.Canvas);
       p := TIGPPen.Create(aclRed, 2);
       b := TIGPSolidBrush.Create(aclAliceBlue);
       r := TIGPRect.Create(20, 20, 100, 60);
       g.FillRectangle(b, r);
       g.DrawRectangle(p, r);
    end;

    end.

    结果如下:

    image

    注意:与Delphi内置的GDI+接口相比,IGDI+明显要简单得多,所有的类全部使用接口,所以不必再考虑对象的释放问题,只需要创建即可,对象会使用Delphi的接口机制实现自动地垃圾收集。

    http://blog.sina.com.cn/s/blog_591968570102vwul.html

  • 相关阅读:
    java环境变量配置 tomcat配置
    asp.net 数据库连接 使用事务处理(一)
    css3 渐变gradient
    asp.net 数据库连接类 (一)
    某某系统HTML脚本植入测试
    BitmapFactory.Options.inSampleSize 的用法
    Comparator和Comparable在排序中的应用(转)
    学习PrintWriter类
    Android使用ListView注意事项
    Android之SurfaceView学习(转)
  • 原文地址:https://www.cnblogs.com/findumars/p/5380281.html
Copyright © 2020-2023  润新知