Delphi 7下IGDIPlus库的使用

 IGDI+是一个免费开源封装微软GDI+功能的Delphi库,该库使得可以用Delphi语言代码快速简短的实现复杂GDI+应用程序。
官方网站:http://www.mitov.com/html/igdi_.html
SourceForge:https://sourceforge.net/projects/igdiplus/ 安装方法:
.首先下载目前最新版的IGDI+,解压到任意目录下,这里我解压到D盘;
.打开Delphi →Tools→Environment Options→Library→Library path,然后点击右边的“...”,添加IGDI+的目录路径,确定完成,如下图所示: 如要在程序中使用IGDI+的话
.首先在单元头uses内包含IGDIPlus,如:uses IGDIPlus;
.在窗体的OnPaint事件中,添加如下测试代码:
procedure TForm1.FormPaint(Sender: TObject);
var
AGraphics: IGPGraphics;
APen: IGPPen;
AFont: IGPFont;
ABrush: IGPSolidBrush;
rc: TPoint;
begin
AGraphics := TGPGraphics.Create(Canvas);
AGraphics.SmoothingMode := SmoothingModeAntiAlias;//指定平滑(抗锯齿)
AGraphics.TextRenderingHint := TextRenderingHintAntiAlias;//指定使用过程中呈现的文本采用反走样
APen := TGPPen.Create($FF000000,);
AGraphics.DrawLine(APen,,,,); APen.Color := $FF0000FF;
APen.Width := ;
AGraphics.DrawEllipse(APen,,,,); Canvas.Font.Name := '微软雅黑';
Canvas.Font.Size := ;
AFont := TGPFont.Create(Canvas.Handle);
ABrush := TGPSolidBrush.Create($FFFF0000);
rc.X := ;
rc.Y := ;
AGraphics.DrawString('无幻博客'+##+'http://blog.csdn.net/akof1314',AFont,rc,ABrush);
end; .运行结果如下图所示: IGDI+库下载:
地址一:http://www.mitov.com/IGDIPlus.zip
地址二:http://download.csdn.net/source/3039922

Delphi GDI+ 绘图

绘图需要有纸、画笔、画刷; Delphi 有 Canvas、Pen、Brush.
Canvas :就是画布, 譬如窗体的 Canvas 属性, 就是窗体的画布;
Pen :是画笔, 可以设置笔色、笔宽等等;
Brush: 是画刷, 可以设置填充颜色等等.
--------------------------------------------------------------------------------
//举例:
{绘制直线}
procedure TForm1.Button1Click(Sender: TObject);
begin
Canvas.Pen.Color := clRed; {设置画笔颜色}
Canvas.Pen.Width := ; {设置画笔宽度}
Canvas.MoveTo(,); {直线起点}
Canvas.LineTo(,); {直线终点}
{这里的 Canvas 是简写, 也可以写做: Self.Canvas 或 Form1.Canvas }
end;
{矩形填充}
procedure TForm1.Button2Click(Sender: TObject);
begin
Canvas.Brush.Color := clYellow; {设置画刷颜色, 也就是填充色}
Canvas.FillRect(ClientRect); {填充窗体客户区}
end;
最好用 TPaintBox 并在其 OnPaint 事件中绘图。而不是在Image控件中Image1.Canvas.Rectangle(,,Image1.Width,Image1.Height); --------------------------------------------------------------------------------
TImage、TPaintBox、TPicture、TBitmap、TCanvas、TGraphic 的关系与区别
TGraphic 是 TBitmap 的父类, 很多绘图函数的参数是 TGraphic, 但我们经常给函数的是 TBitmap;
TBitmap 的很多功能都是继承自 TGraphic, 譬如:
Width、Height、LoadFromFile、SaveToFile、LoadFromStream、SaveToStream;
还有 Palette(调色板)、Transparent(是否透明) 等等.
TGraphic 实用举例: --------------------------------------------------------------------------------
var
g: TGraphic;
begin
g := TBitmap.Create;
g.LoadFromFile('c:\temp\test.bmp');
Self.Canvas.StretchDraw(ClientRect, g);
g.Free;
end;
-------------------------------------------------------------------------------- TCanvas 是一个绘图表面, 像画圆、画方、画笔、画刷等等都是它的功能;
控件的 Canvas 属性就是一个 TCanvas, 譬如: --------------------------------------------------------------------------------
var
cvs: TCanvas;
begin
cvs := Self.Canvas;
cvs.Brush.Color := clYellow;
cvs.Font.Color := clRed;
cvs.Font.Name := '宋体';
cvs.Font.Style := [fsBold];
cvs.Font.Size := ;
cvs.TextOut(, , '万一的 Delphi 博客');
end;
-------------------------------------------------------------------------------- 有些控件没有直接给 Canvas 属性, 我们也可以通过 TCanvas 获取它的绘图表面;
一切看得见的控件都应该有绘图表面, 不然系统是怎么画的?
譬如 TPanel 和 TButton 就没有 Canvas 属性, 没有是因为不常用, 如果需要可以这样: --------------------------------------------------------------------------------
var
cvs: TCanvas;
begin
cvs := TCanvas.Create;
cvs.Handle := GetDC(Panel1.Handle);
cvs.Pen.Width := ;
cvs.Pen.Color := clRed;
cvs.Brush.Color := clYellow;
cvs.Rectangle(, , , );
cvs.Free;
end;
-------------------------------------------------------------------------------- 再说 TBitmap, 它从 TGraphic 继承, 同时又把 TCanvas 纳为自己的属性;
所以它有了处理图片和绘图的双重功能!
给 TBitmap 也举个例子吧: --------------------------------------------------------------------------------
var
bit: TBitmap;
begin
bit := TBitmap.Create;
bit.LoadFromFile('c:\temp\test.bmp');
bit.Canvas.Brush.Style := bsClear;
bit.Canvas.Pen.Color := clRed;
bit.Canvas.Pen.Width := ;
bit.Canvas.Ellipse(, , , );
Self.Canvas.Draw(, , bit);
bit.Free;
end;
-------------------------------------------------------------------------------- TPicture 是为了处理更多种格式的图片(譬如: ico、wmf 等)而存在的;
但它把 TGraphic、TCanvas、TBitmap 的功能通通借用过来, 所以功能更强大.
TPicture 和 TGraphic 重复的功能(譬如: LoadFromFile)都是内部调用的 TGraphic;
但如果要给它绘图, 需要调用: TPicture.Bitmap.Canvas.
下面的例子是用 TPicture 画了个十字图标(显示并保存起来): --------------------------------------------------------------------------------
var
pic: TPicture;
begin
pic := TPicture.Create;
pic.Bitmap.SetSize(, );
pic.Bitmap.Canvas.Pen.Color := clRed;
pic.Bitmap.Canvas.Pen.Width := ;
pic.Bitmap.Canvas.MoveTo(, );
pic.Bitmap.Canvas.LineTo(, );
pic.Bitmap.Canvas.MoveTo(, );
pic.Bitmap.Canvas.LineTo(, );
Self.Canvas.Draw(, , pic.Graphic);
pic.SaveToFile('c:\temp\test.ico');
pic.Free;
end;
-------------------------------------------------------------------------------- TImage 则主要是为了显示图片, 它主要包含的是 TPicture, 有了 TPicture 就有了上面的一切;
但因它是从 TControl -> TGraphicControl 继承下来的, 所以它具备了控件的基本能力(事件、消息等等).
TPaintBox 主要用于绘图, 没有处理图片的能力, 所以只包含了 TCanvas;
它也是从 TControl -> TGraphicControl 继承, 是能够交互的控件了.
很显然, TImage 比 TPaintBox 的能力强大; 但仅就绘图来讲, 还是 TPaintBox 轻便些.

Delphi GDI+ 文本输出

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, CheckLst;
type
TForm1 = class(TForm)
CheckListBox1: TCheckListBox;
procedure FormPaint(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure CheckListBox1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses GDIPOBJ, GDIPAPI;
var fs: Integer;
procedure TForm1.CheckListBox1Click(Sender: TObject);
const
fsArr: array[..] of Integer = (FontStyleRegular,
FontStyleBold,
FontStyleItalic,
FontStyleBoldItalic,
FontStyleUnderline,
FontStyleStrikeout);
var
i: Integer;
begin
fs := ;
for i := 0to CheckListBox1.Items.Count - 1do
if CheckListBox1.Checked[i] then
fs := fs or fsArr[i];
Repaint;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
CheckListBox1.Align := alLeft;
CheckListBox1.Items.CommaText := 'FontStyleRegular,' +
'FontStyleBold,' +
'FontStyleItalic,' +
'FontStyleBoldItalic,' +
'FontStyleUnderline,' +
'FontStyleStrikeout';
CheckListBox1.Checked[] := True;
end;
procedure TForm1.FormPaint(Sender: TObject);
var
g: TGPGraphics;
sb: TGPSolidBrush;
font: TGPFont;
begin
g := TGPGraphics.Create(Canvas.Handle);
sb := TGPSolidBrush.Create(aclRed);
font := TGPFont.Create('微软雅黑', , fs);
g.DrawString('Delphi', -, font, MakePoint(CheckListBox1.Width + 0.0, ), sb);
font.Free;
sb.Free;
g.Free;
end;
end.
FontStyle = Integer;
const
FontStyleRegular = Integer(); {普通文本}
FontStyleBold = Integer(); {加粗文本}
FontStyleItalic = Integer(); {倾斜文本}
FontStyleBoldItalic = Integer(); {加粗并倾斜文本}
FontStyleUnderline = Integer(); {带下划线的文本}
FontStyleStrikeout = Integer(); {中间有直线通过的文本}
Type
TFontStyle = FontStyle;
文本样式类型表:
Delphi 微软 说明
FontStyleBold Bold 加粗文本。
FontStyleItalic Italic 倾斜文本。
FontStyleRegular Regular 普通文本。
FontStyleStrikeout Strikeout 中间有直线通过的文本。
FontStyleUnderline Underline 带下划线的文本。
坐标单位类型表:
Delphi 微软 说明
UnitDisplay Display 指定显示设备的度量单位。通常,视频显示使用的单位是像素;打印机使用的单位是 / 英寸。
UnitDocument Document 将文档单位(/ 英寸)指定为度量单位。
UnitInch Inch 将英寸指定为度量单位。
UnitMillimeter Millimeter 将毫米指定为度量单位。
UnitPixel Pixel 将设备像素指定为度量单位。
UnitPoint Point 将打印机点(/ 英寸)指定为度量单位。
UnitWorld World 将世界坐标系单位指定为度量单位。
文本呈现质量模式:
Delphi 微软 说明
TextRenderingHintAntiAlias AntiAlias 在无提示的情况下使用每个字符的消除锯齿效果标志符号位图来绘制字符。由于采用了 AntiAlias,质量会得到改善。由于关闭了提示,主干宽度差可能会比较明显。
TextRenderingHintAntiAliasGridFit AntiAliasGridFit 在有提示的情况下使用每个字符的消除锯齿效果标志符号位图来绘制字符。由于采用了 AntiAlias,质量会得到大大改善,但同时会增加性能成本。
TextRenderingHintClearTypeGridFit ClearTypeGridFit 在有提示的情况下使用每个字符的标志符号 ClearType 位图来绘制字符。这是质量最高的设置。用于利用 ClearType 字体功能。
TextRenderingHintSingleBitPerPixel SingleBitPerPixel 使用每个字符的标志符号位图来绘制字符。不使用提示。
TextRenderingHintSingleBitPerPixelGridFit SingleBitPerPixelGridFit 使用每个字符的标志符号位图来绘制字符。提示用于改善字符在主干和弯曲部分的外观。
TextRenderingHintSystemDefault SystemDefault 在有系统默认呈现提示的情况下使用每个字符的标志符号位图来绘制字符。将采用用户为系统选择的任何字体修匀设置来绘制文本。
//颜色透明度var g: TGPGraphics; sb: TGPSolidBrush;begin g := TGPGraphics.Create(Canvas.Handle); sb := TGPSolidBrush.Create(MakeColor(128,255,0,0)); {128表示半透明} g.FillRectangle(sb,10,10,100,100); sb.Free; g.Free;end;
--------------------------------------------------------------------------------
//使用 GDI+ 的颜色类型var g: TGPGraphics; sb: TGPSolidBrush; color: TGPColor; {其实颜色是 DWORD 类型的}begin g := TGPGraphics.Create(Canvas.Handle); color := aclRed; sb := TGPSolidBrush.Create(color); g.FillRectangle(sb,10,10,100,100); sb.Free; g.Free;end;

Delphi GDI(一)的更多相关文章

  1. Delphi GDI+ Library

    GDI+ LibraryThis library enables GDI+ functionality for Delphi 2009 and later. It differs from other ...

  2. Delphi GDI+ 安装方法

    [转]Delphi GDI+ 安装方法转自:万一博客(http://www.cnblogs.com/del/)GDI+ 是 Windows 的一个函数库, 来自 Windows\System32\GD ...

  3. Delphi GDI+基本用法总结

    GDI+以前只是听说过,还没怎么用过,这段时间用了用,觉得挺好用的.在这里总结一下.留个备忘. GDI+(Graphics Device Interface plus)是Windows XP中的一个子 ...

  4. Delphi+GDI

    源:Delphi 初试GDI+学习笔记 Delphi 深入GDI+学习笔记

  5. Delphi GDI对象之绘制位图

    http://www.cnblogs.com/pchmonster/archive/2012/07/06/2579334.html 绘制位图(Drawing Bitmaps) 绘制位图听起来似乎很难, ...

  6. Delphi GDI对象之绘制文本

    转载:http://www.cnblogs.com/pchmonster/archive/2012/07/06/2579185.html 基本绘图操作(Basic Drawing Operations ...

  7. delphi GDI 图片压缩代码 据说是位图缩放保持原图视觉效果最好的算法

    delphi 图片压缩代码 据说是位图缩放保持原图视觉效果最好的算法 若有更好的,请大神留言我也学习下,感谢! uses WinAPI.GDIPAPI, WinAPI.GDIPOBJ; var  Bi ...

  8. Delphi GDI对象之剪切区域

    原文链接: http://www.cnblogs.com/pchmonster/archive/2012/07/05/2577627.html 剪切区域(Clipping Regions) Regio ...

  9. Delphi GDI对象之脱屏位图(Offscreen Bitmaps),也叫内存位图

    http://www.cnblogs.com/pchmonster/archive/2012/07/09/2583613.html 脱屏位图(Offscreen Bitmaps) 脱屏位图,也叫内存位 ...

随机推荐

  1. 阿里linux-Centos各版本下载

    https://mirrors.aliyun.com/centos/7/isos/x86_64/ Index of /centos/7/isos/x86_64/ ../ 0_README.txt 16 ...

  2. Java高并发网络编程(五)Netty应用

    推送系统 一.系统设计 二.拆包和粘包 粘包.拆包表现形式 现在假设客户端向服务端连续发送了两个数据包,用packet1和packet2来表示,那么服务端收到的数据可以分为三种,现列举如下: 第一种情 ...

  3. 【leetcode】963. Minimum Area Rectangle II

    题目如下: Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from ...

  4. leetcood学习笔记-20

    python字符串与列表的相互转换   学习内容: 1.字符串转列表 2.列表转字符串 1. 字符串转列表 str1 = "hi hello world" print(str1.s ...

  5. 冲刺$\mathfrak{CSP-S}$集训模拟赛总结

    开坑.手懒并不想继续一场考试一篇文. 既没必要也没时间侧边栏的最新随笔题解反思相间也丑 而且最近越来越懒了竟然都不写题解了……开坑也是为了督促自己写题解. 并不想长篇大论.简要题解也得写啊QAQ. 目 ...

  6. 「题解」:$Six$

    问题 A: Six 时间限制: 1 Sec  内存限制: 512 MB 题面 题面谢绝公开. 题解 来写一篇正经的题解. 每一个数对于答案的贡献与数本身无关,只与它包含了哪几个质因数有关. 所以考虑二 ...

  7. Hadoop-HDFS的伪分布式和完全分布式集群搭建

    Hadoop-HDFSHDFS伪分布式集群搭建步骤一.配置免密登录 ssh-keygen -t rsa1一句话回车到底 ssh-copy-id -i ~/.ssh/id_rsa.pub root@no ...

  8. switch type 类型判断

    golang 语言中 也有 类是 javascript 的 typeof 判断类型的 方法 比如 func (a interface{}){ //第一种 if inst,ok:=a.(TypeA);o ...

  9. es批量索引

    使用Python操作Elasticsearch数据索引的教程 这篇文章主要介绍了使用Python操作Elasticsearch数据索引的教程,Elasticsearch处理数据索引非常高效,要的朋友可 ...

  10. Ubuntu 16.04系统上修改Docker镜像的存储路径 (转)

    转自:https://blog.csdn.net/qihongchao/article/details/80651492 dba专门挂了一个硬盘让我放项目(测试环境)因为系统空间比较小,希望把dock ...