//方法
IGPGraphics.DrawLine();               { 画线 }
IGPGraphics.DrawLines();              { 画一组线 }
IGPGraphics.DrawArc();                { 画弧线 }
IGPGraphics.DrawBezier();             { 画 Bezier 线 }
IGPGraphics.DrawBeziers();            { 画一组 Bezier 线 }
IGPGraphics.DrawRectangle();          { 画矩形 }
IGPGraphics.DrawRectangles();         { 画一组矩形 }
IGPGraphics.DrawEllipse();            { 画椭圆 }
IGPGraphics.DrawPie();                { 画饼形 }
IGPGraphics.DrawPolygon();            { 画多边形 }
IGPGraphics.DrawCurve();              { 画曲线 }
IGPGraphics.DrawClosedCurve();        { 画闭合曲线 }
IGPGraphics.DrawPath();               { 画路径 }

IGPGraphics.FillRectangle();          { 填充矩形 }
IGPGraphics.FillRectangles();         { 填充一组矩形 }
IGPGraphics.FillPolygon();            { 填充多边形 }
IGPGraphics.FillEllipse();            { 填充椭圆 }
IGPGraphics.FillPie();                { 填充饼形 }
IGPGraphics.FillPath();               { 填充路径 }
IGPGraphics.FillClosedCurve();        { 填充闭合曲线 }
IGPGraphics.FillRegion();             { 填充区域 }

IGPGraphics.DrawImage();              { 呈现图像 }
IGPGraphics.DrawCachedBitmap();       { 呈现 CachedBitmap 图像 }
IGPGraphics.AddMetafileComment();     { 向当前 Metafile 添加注释 }
IGPGraphics.EnumerateMetafile();      { 枚举 Metafile 中的图形命令 }

IGPGraphics.DrawString();             { 绘制文本 }
IGPGraphics.MeasureString();          { 获取指定格式的字符串需要的矩形 }
IGPGraphics.DrawDriverString();       { 绘制可指定间距的文本 }
IGPGraphics.MeasureDriverString();    { 获取可指定间距文本所需要的矩形范围 }
IGPGraphics.MeasureCharacterRanges(); { 获取指定字符所在的区域 }

IGPGraphics.SetClip();                { 设置 Graphics 的绘图区域 }
IGPGraphics.IntersectClip();          { 通过相交运算设置新的剪切区域 }
IGPGraphics.ExcludeClip();            { 减去剪切区域 }
IGPGraphics.ResetClip;                { 重置剪切区域 }
IGPGraphics.TranslateClip();          { 平移剪切区域 }
IGPGraphics.IsVisible();              { 判断指定的点或矩形是否包含在 Graphics 可见剪切区域内 }

IGPGraphics.Clear();                  { 清除绘图表面并以指定背景色填充 }
IGPGraphics.Save;                     { 保存 Graphics 当前状态 }
IGPGraphics.Restore();                { 恢复由 Save 保存的状态 }
IGPGraphics.Flush();                  { 强制执行所有挂起的图形操作并立即返回而不等待操作完成 }
IGPGraphics.GetNearestColor();        { 获取与指定颜色参数最接近的系统颜色 }
IGPGraphics.GetHDC;                   { 获取 Graphics 关联的 HDC }
IGPGraphics.ReleaseHDC();             { 释放 Graphics 关联的 HDC }
IGPGraphics.GetRenderingOrigin();     { 获取原点 }
IGPGraphics.SetRenderingOrigin();     { 设置原点 }

IGPGraphics.MultiplyTransform();      { 将 Graphics 的世界变换乘以指定的 Matrix }
IGPGraphics.TranslateTransform();     { 平移变换 }
IGPGraphics.ScaleTransform();         { 放缩变换 }
IGPGraphics.RotateTransform();        { 旋转变换 }
IGPGraphics.ResetTransform;           { 重置变换 }

IGPGraphics.BeginContainer();         { 保存之前的状态, 并开始一个新的状态 }
IGPGraphics.EndContainer();           { 还原由 BeginContainer 保存的状态 }

IGPGraphics.TransformPoints();        { 将点数组转换坐标空间 }

//属性
IGPGraphics.DpiX;                     { 获取 Graphics 水平分辨率 }
IGPGraphics.DpiY;                     { 获取 Graphics 垂直分辨率 }
IGPGraphics.RenderingOrigin;          { 原点 }
IGPGraphics.PageScale;                { 获取或设置 Graphics 的全局单位和页单位之间的比例 }
IGPGraphics.PageUnit;                 { 获取或设置 Graphics 中页坐标的度量单位 }
IGPGraphics.Transform;                { 获取或设置矩阵变换 }

IGPGraphics.CompositingMode;          { 前景色与背景色的合成混合模式 }
IGPGraphics.InterpolationMode;        { 插补模式 }
IGPGraphics.PixelOffsetMode;          { 像素的偏移模式 }
IGPGraphics.CompositingQuality;       { 图像合成质量 }
IGPGraphics.SmoothingMode;            { 绘图质量 }
IGPGraphics.TextRenderingHint;        { 获取或设置文本呈现模式 }
IGPGraphics.TextContrast;             { 获取或设置文本灰度校正值(消除锯齿和 ClearType 文本的伽玛值校正: 0..12, 默认4) }

IGPGraphics.Clip;                     { 获取或设置 Graphics 的绘图区域 }
IGPGraphics.ClipBounds;               { 获取剪切区域的矩形边界; 浮点型 }
IGPGraphics.ClipBoundsI;              { 获取剪切区域的矩形边界; 整型 }
IGPGraphics.VisibleClipBounds;        { 可见的剪切区域的矩形边界; 浮点型 }
IGPGraphics.VisibleClipBoundsI;       { 可见的剪切区域的矩形边界; 整型 }
IGPGraphics.IsClipEmpty;              { 剪切区域是否为空 }
IGPGraphics.IsVisibleClipEmpty;       { 可见的剪切区域是否为空 }


关于剪切区域的例子:



uses GdiPlus;

var
  Graphics: IGPGraphics;
  Image: IGPImage;

procedure TForm1.FormCreate(Sender: TObject);
var
  Rect1, Rect2: TGPRect;
  Path1, Path2: IGPGraphicsPath;
begin
  Image := TGPImage.Create('C:\GdiPlusImg\ImageFileSmall.jpg');

  Graphics := TGPGraphics.Create(Handle);
  Rect1.Initialize(20, 20, 120, 120);
  Rect2.Initialize(120, 20, 120, 120);

  Path1 := TGPGraphicsPath.Create;
  Path2 := TGPGraphicsPath.Create;
  Path1.AddEllipse(Rect1);
  Path2.AddEllipse(Rect2);

  Graphics.SetClip(Path1);
  Graphics.SetClip(Path2, CombineModeUnion);
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  if not Graphics.IsVisibleClipEmpty then
  begin
    Graphics.SetClip(Graphics.VisibleClipBoundsI, CombineModeIntersect);
    Graphics.DrawImage(Image, 10, 10);
  end;
end;


PageUnit、PageScale 测试:



uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var
  Graphics: IGPGraphics;
  Pen: IGPPen;
  Rect: TGPRect;
begin
  Graphics := TGPGraphics.Create(Handle);
  Rect.Initialize(20, 20, 200, 150);

  Pen := TGPPen.Create($FFC0C0C0, 3);
  Graphics.DrawRectangle(Pen, Rect);

  Graphics.PageUnit := UnitDocument; { PageScale 只在页面坐标下有效 }
  Graphics.PageScale := 1.0; //默认
  Pen.Color := $FF0000FF;
  Graphics.DrawRectangle(Pen, Rect);

  Pen.Color := $FFFF0000;
  Graphics.PageScale := 2.0;
  Graphics.DrawRectangle(Pen, Rect);
end;


BeginContainer、EndContainer 前者是开始变换, 后者是重置到变换之前的状态:



uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var
  Graphics: IGPGraphics;
  Pen: IGPPen;
  Rect: TGPRect;
begin
  Graphics := TGPGraphics.Create(Handle);
  Rect.Initialize(60, 60, 100, 100);

  Pen := TGPPen.Create($FFC0C0C0, 2);
  Graphics.DrawRectangle(Pen, Rect);

  Pen.Color := $FF0000FF;
  Tag := Graphics.BeginContainer;
    Graphics.RotateTransform(18);
    Graphics.DrawRectangle(Pen, Rect);
  Graphics.EndContainer(Tag);

  Pen.Color := $FFFF0000;
  Tag := Graphics.BeginContainer;
    Graphics.RotateTransform(-18);
    Graphics.DrawRectangle(Pen, Rect);
  Graphics.EndContainer(Tag);
end;

//用 Save 和 Restore 重复实现的代码:
uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var
  Graphics: IGPGraphics;
  Pen: IGPPen;
  Rect: TGPRect;
begin
  Graphics := TGPGraphics.Create(Handle);
  Rect.Initialize(60, 60, 100, 100);

  Pen := TGPPen.Create($FFC0C0C0, 2);
  Graphics.DrawRectangle(Pen, Rect);

  Pen.Color := $FF0000FF;
  Tag := Graphics.Save;
  Graphics.RotateTransform(18);
  Graphics.DrawRectangle(Pen, Rect);
  Graphics.Restore(Tag);

  Pen.Color := $FFFF0000;
  Graphics.Restore(Tag);
  Graphics.RotateTransform(-18);
  Graphics.DrawRectangle(Pen, Rect);
  Graphics.Restore(Tag);
end;


原点(RenderingOrigin 它变换是两回事)与阴影画刷的测试:



uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var
  Graphics: IGPGraphics;
  Brush: IGPHatchBrush;
  Rect: TGPRect;
begin
  Graphics := TGPGraphics.Create(Handle);
  Brush := TGPHatchBrush.Create(HatchStyleSolidDiamond, $FF8B0000, $FFFFD700);

  Rect.Initialize(10, 10, 108, 60);
  Graphics.SetRenderingOrigin(0, 0); //这是默认值
  Graphics.FillRectangle(Brush, Rect);

  Graphics.TranslateTransform(0, Rect.Y + Rect.Height);
  Graphics.SetRenderingOrigin(Rect.X, Rect.Y + Trunc(Graphics.Transform.OffsetY));
  Graphics.FillRectangle(Brush, Rect);
end;

posted on 2009-12-21 19:49  万一  阅读(6118)  评论(0编辑  收藏  举报