文档章节

用 GDI 操作 EMF 文件[7]: EnumEnhMetaFile、PlayEnhMetaFileRecord - 枚举文件中的图形命令

涂孟超
 涂孟超
发布于 2014/09/26 15:31
字数 836
阅读 39
收藏 0
EnumEnhMetaFile(
  DC: HDC;                       {目标设备句柄; 如果回调函数不需要回放, 该参数为 0}
  Emf: HENHMETAFILE;             {图元文件句柄}
  EnhMetaFunc: TFNEnhMFEnumProc; {回调函数指针; 回调函数格式见下}
  Data: Pointer;                 {自定义数据指针}
  const Rect: TRect              {要输出的尺寸; 如果 DC=0 该参数会被忽略}
): BOOL;

//EnumEnhMetaFile 使用的回调函数格式及参数, PlayEnhMetaFileRecord 基本就是使用这些参数:
function EnhMetaFunc(
  DisplaySurface: HDC;                {目标设备句柄; 如果回调函数不需要回放, 该参数为 0}
  var MetafileTable: THandleTable;    {句柄表数组指针, 数组包含 HGDIOBJ 对象(画笔、画刷等); 元素1是文件自身句柄}
  var MetafileRecord: TEnhMetaRecord; {图元文件记录 TEnhMetaRecord 指针, TEnhMetaRecord 结构见下表}
  ObjectCount: Integer;               {对象句柄数目, 即句柄表 MetafileTable 中图形对象的数目}
  var Data: Longint                   {自定义数据指针}
): Integer; stdcall;

//TEnhMetaRecord 结构:
tagENHMETARECORD = packed record
  iType: DWORD;                {类型}
  nSize: DWORD;                {尺寸}
  dParm: array[0..0] of DWORD; {参数数组}
end;

//TEnhMetaRecord.iType 的可能值:
EMR_HEADER                  = 1;
EMR_POLYBEZIER              = 2;
EMR_POLYGON                 = 3;
EMR_POLYLINE                = 4;
EMR_POLYBEZIERTO            = 5;
EMR_POLYLINETO              = 6;
EMR_POLYPOLYLINE            = 7;
EMR_POLYPOLYGON             = 8;
EMR_SETWINDOWEXTEX          = 9;
EMR_SETWINDOWORGEX          = 10;
EMR_SETVIEWPORTEXTEX        = 11;
EMR_SETVIEWPORTORGEX        = 12;
EMR_SETBRUSHORGEX           = 13;
EMR_EOF                     = 14;
EMR_SETPIXELV               = 15;
EMR_SETMAPPERFLAGS          = $10;
EMR_SETMAPMODE              = 17;
EMR_SETBKMODE               = 18;
EMR_SETPOLYFILLMODE         = 19;
EMR_SETROP2                 = 20;
EMR_SETSTRETCHBLTMODE       = 21;
EMR_SETTEXTALIGN            = 22;
EMR_SETCOLORADJUSTMENT      = 23;
EMR_SETTEXTCOLOR            = 24;
EMR_SETBKCOLOR              = 25;
EMR_OFFSETCLIPRGN           = 26;
EMR_MOVETOEX                = 27;
EMR_SETMETARGN              = 28;
EMR_EXCLUDECLIPRECT         = 29;
EMR_INTERSECTCLIPRECT       = 30;
EMR_SCALEVIEWPORTEXTEX      = 31;
EMR_SCALEWINDOWEXTEX        = 32;
EMR_SAVEDC                  = 33;
EMR_RESTOREDC               = 34;
EMR_SETWORLDTRANSFORM       = 35;
EMR_MODIFYWORLDTRANSFORM    = 36;
EMR_SELECTOBJECT            = 37;
EMR_CREATEPEN               = 38;
EMR_CREATEBRUSHINDIRECT     = 39;
EMR_DELETEOBJECT            = 40;
EMR_ANGLEARC                = 41;
EMR_ELLIPSE                 = 42;
EMR_RECTANGLE               = 43;
EMR_ROUNDRECT               = 44;
EMR_ARC                     = 45;
EMR_CHORD                   = 46;
EMR_PIE                     = 47;
EMR_SELECTPALETTE           = 48;
EMR_CREATEPALETTE           = 49;
EMR_SETPALETTEENTRIES       = 50;
EMR_RESIZEPALETTE           = 51;
EMR_REALIZEPALETTE          = 52;
EMR_EXTFLOODFILL            = 53;
EMR_LINETO                  = 54;
EMR_ARCTO                   = 55;
EMR_POLYDRAW                = 56;
EMR_SETARCDIRECTION         = 57;
EMR_SETMITERLIMIT           = 58;
EMR_BEGINPATH               = 59;
EMR_ENDPATH                 = 60;
EMR_CLOSEFIGURE             = 61;
EMR_FILLPATH                = 62;
EMR_STROKEANDFILLPATH       = 63;
EMR_STROKEPATH              = $40;
EMR_FLATTENPATH             = 65;
EMR_WIDENPATH               = 66;
EMR_SELECTCLIPPATH          = 67;
EMR_ABORTPATH               = 68;
EMR_GDICOMMENT              = 70;
EMR_FILLRGN                 = 71;
EMR_FRAMERGN                = 72;
EMR_INVERTRGN               = 73;
EMR_PAINTRGN                = 74;
EMR_EXTSELECTCLIPRGN        = 75;
EMR_BITBLT                  = 76;
EMR_STRETCHBLT              = 77;
EMR_MASKBLT                 = 78;
EMR_PLGBLT                  = 79;
EMR_SETDIBITSTODEVICE       = 80;
EMR_STRETCHDIBITS           = 81;
EMR_EXTCREATEFONTINDIRECTW  = 82;
EMR_EXTTEXTOUTA             = 83;
EMR_EXTTEXTOUTW             = 84;
EMR_POLYBEZIER16            = 85;
EMR_POLYGON16               = 86;
EMR_POLYLINE16              = 87;
EMR_POLYBEZIERTO16          = 88;
EMR_POLYLINETO16            = 89;
EMR_POLYPOLYLINE16          = 90;
EMR_POLYPOLYGON16           = 91;
EMR_POLYDRAW16              = 92;
EMR_CREATEMONOBRUSH         = 93;
EMR_CREATEDIBPATTERNBRUSHPT = 94;
EMR_EXTCREATEPEN            = 95;
EMR_POLYTEXTOUTA            = 96;
EMR_POLYTEXTOUTW            = 97;
EMR_SETICMMODE              = 98;
EMR_CREATECOLORSPACE        = 99;
EMR_SETCOLORSPACE           = 100;
EMR_DELETECOLORSPACE        = 101;
EMR_GLSRECORD               = 102;
EMR_GLSBOUNDEDRECORD        = 103;
EMR_PIXELFORMAT             = 104;
EMR_DRAWESCAPE              = 105;
EMR_EXTESCAPE               = 106;
EMR_STARTDOC                = 107;
EMR_SMALLTEXTOUT            = 108;
EMR_FORCEUFIMAPPING         = 109;
EMR_NAMEDESCAPE             = 110;
EMR_COLORCORRECTPALETTE     = 111;
EMR_SETICMPROFILEA          = 112;
EMR_SETICMPROFILEW          = 113;
EMR_ALPHABLEND              = 114;
EMR_ALPHADIBBLEND           = 115;
EMR_TRANSPARENTBLT          = 116;
EMR_TRANSPARENTDIB          = 117;
EMR_GRADIENTFILL            = 118;
EMR_SETLINKEDUFIS           = 119;
EMR_SETTEXTJUSTIFICATION    = 120;

 
 
 
 
 

 

 

  
在下面的例子中, 先在内存中建立了一个图元文件, 再其中绘制了直线、矩形和两个椭圆;

然后控制显示了图元文件的部分及全部.

运行效果图:



代码文件:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    RadioGroup1: TRadioGroup;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure RadioGroup1Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

var
  HMetaFile: HENHMETAFILE; {EMF 文件句柄}
  RadioGroupItemIndex: Integer = -1;

//EnumEnhMetaFile 的回调函数
function MyEnhMetaFunc(DisplaySurface: HDC; var MetafileTable: THandleTable;
  var MetafileRecord: TEnhMetaRecord; ObjectCount: Integer; var Data: Longint
  ): Integer; stdcall;
var
  itype: Integer;
begin
  case RadioGroupItemIndex of
    1: itype := EMR_RECTANGLE;
    2: itype := EMR_ELLIPSE;
  end;
  if MetafileRecord.iType = itype then
  begin
    PlayEnhMetaFileRecord(DisplaySurface, MetafileTable, MetafileRecord, ObjectCount);
    Result := 1;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  MetaFileDC: HDC;
begin
  {文件建立在内存}
  MetaFileDC := CreateEnhMetaFile(0, nil, nil, nil);
  MoveToEx(MetaFileDC, 0, 0, nil);
  LineTo(MetaFileDC, 100, 100);
  {矩形}
  Rectangle(MetaFileDC, 10, 10, 30, 30);
  {椭圆}
  Ellipse(MetaFileDC, 30, 30, 50, 50);
  Ellipse(MetaFileDC, 45, 45, 65, 65);

  HMetaFile := CloseEnhMetaFile(MetaFileDC);
  DeleteObject(MetaFileDC);

  RadioGroup1.Items.CommaText := '整个图元文件,其中的矩形,其中的椭圆';
end;

procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
  Repaint;
  RadioGroupItemIndex := RadioGroup1.ItemIndex;
  if RadioGroupItemIndex = 0 then
    PlayEnhMetaFile(Canvas.Handle, HMetaFile, ClientRect)
  else
    EnumEnhMetaFile(Canvas.Handle, HMetaFile, @MyEnhMetaFunc, nil, ClientRect);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  DeleteEnhMetaFile(HMetaFile);
end;

end.

 
 
 
 
 

 

 

  
窗体文件:
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 197
  ClientWidth = 325
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  Position = poDesktopCenter
  OnCreate = FormCreate
  OnDestroy = FormDestroy
  PixelsPerInch = 96
  TextHeight = 13
  object RadioGroup1: TRadioGroup
    Left = 216
    Top = 8
    Width = 101
    Height = 113
    Caption = 'RadioGroup1'
    TabOrder = 0
    OnClick = RadioGroup1Click
  end
end

 
 
 
 
 

 

 

  

本文转载自:http://www.cnblogs.com/del/archive/2008/06/05/1214285.html

涂孟超
粉丝 12
博文 2011
码字总数 14107
作品 0
深圳
程序员
私信 提问
Graphical Modeling Framework简介

本文假设读者有Eclipse平台应用程序开发经验,了解Eclipse平台的插件机制,使用EMF和GEF开发过应用程序。在本文中,“Eclipse应用程序”等价于“Eclipse插件”。 Eclipse是一个开源的平台,从...

青夜之衫
2017/12/07
0
0
杂谈SharpDx中的WIC组件——我们需要WIC的图片编码功能么?

在前文 SharpDX之Direct2D教程II——加载位图文件和保存位图文件 中,发现在VB2010中不能很好的运用SharpDx中的WIC组件进行图片的编码工作。可能是我的设置问题,也可能是SharpDx对VB2010支持...

万仓一黍
2013/10/08
0
0
VC实现多格式图像的转换

色彩鲜艳漂亮的高品质图像,一个个形象生动的Windows图标,高速运动、活灵活现的三维动画,这些无一不显示出程序设计者的艺术才华。在程序设计中,图像处理已经成为每个程序员的必修课。 在V...

余二五
2017/11/06
0
0
VC 6.0 配置和使用gdi+

GDI+ GDI+是Windows XP中的一个子系统,它主要负责在显示屏幕和打印设备输出有关信息,它是一组通过C++类实现的应用程序编程接口。顾名思义,GDI+是以前版本GDI的继承者,出于兼容性考虑,W...

junwong
2012/03/23
1K
0
GDI+图像处理学习笔记——改变图像的透明度

GDI+是WindowsXp和windows Server 2003中的一个子系统,主要用于处理系统的绘制消息。GDI+是GDI的扩展,其继承了GDI的有点并在其基础上进行了改进,包括增加了一些GDI无法绘制的图形函数,同...

晨曦之光
2012/05/23
533
0

没有更多内容

加载失败,请刷新页面

加载更多

PostgreSQL 11.3 locking

rudi
今天
5
0
Mybatis Plus sql注入器

一、继承AbstractMethod /** * @author beth * @data 2019-10-23 20:39 */public class DeleteAllMethod extends AbstractMethod { @Override public MappedStatement injectMap......

一个yuanbeth
今天
10
1
一次写shell脚本的经历记录——特殊字符惹的祸

本文首发于微信公众号“我的小碗汤”,扫码文末二维码即可关注,欢迎一起交流! redis在容器化的过程中,涉及到纵向扩pod实例cpu、内存以及redis实例的maxmemory值,statefulset管理的pod需要...

码农实战
今天
4
0
为什么阿里巴巴Java开发手册中不建议在循环体中使用+进行字符串拼接?

之前在阅读《阿里巴巴Java开发手册》时,发现有一条是关于循环体中字符串拼接的建议,具体内容如下: 那么我们首先来用例子来看看在循环体中用 + 或者用 StringBuilder 进行字符串拼接的效率...

武培轩
今天
8
0
队列-链式(c/c++实现)

队列是在线性表功能稍作修改形成的,在生活中排队是不能插队的吧,先排队先得到对待,慢来得排在最后面,这样来就形成了”先进先出“的队列。作用就是通过伟大的程序员来实现算法解决现实生活...

白客C
今天
81
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部