API 图像函数(delphi) 联系客服

发布时间 : 星期二 文章API 图像函数(delphi)更新完毕开始阅读

var

MetaFileDC: HDC; begin

{建立并写入说明}

MetaFileDC := CreateEnhMetaFile(0, PChar(Path), nil, PChar(Description)); {绘图}

Rectangle(MetaFileDC, 11, 11, 111, 111); {结束编辑、保存文件, 并返回文件句柄}

HMetaFile := CloseEnhMetaFile(MetaFileDC); {删除 DC}

DeleteObject(MetaFileDC); end;

{读取 EMF 文件的说明}

procedure TForm1.Button1Click(Sender: TObject); var

DescriptionSize: Integer; {说明段的大小} DescriptionBuf: PChar; {接受说明的内存指针} begin {获取大小}

DescriptionSize := GetEnhMetaFileDescription(HMetaFile, 0, nil); {分配内存}

GetMem(DescriptionBuf, DescriptionSize); {获取说明}

GetEnhMetaFileDescription(HMetaFile, DescriptionSize, DescriptionBuf); {显示说明}

ShowMessage(DescriptionBuf); {ABCDE} {释放内存}

FreeMem(DescriptionBuf); end;

{绘制在窗体}

procedure TForm1.Button2Click(Sender: TObject); begin

PlayEnhMetaFile(Canvas.Handle, HMetaFile, Rect(11,11,111,111)); end;

{删除 EMF 文件句柄}

procedure TForm1.FormDestroy(Sender: TObject); begin

DeleteEnhMetaFile(HMetaFile); end; end.

用 GDI 操作 EMF 文件[6]: GetEnhMetaFileHeader - 获取 EMF 的头文件

//增强图元文件的头文件结构 TEnhMetaHeader: tagENHMETAHEADER = packed record iType: DWORD; {记录类型} nSize: DWORD; {结构大小}

rclBounds: TRect; {外接矩形(单位是像素)} rclFrame: TRect; {图片矩形(单位是 0.1 毫米)} dSignature: DWORD; {文件签名} nVersion: DWORD; {文件版本} nBytes: DWORD; {文件尺寸} nRecords: DWORD; {记录数} nHandles: Word; {句柄数} sReserved: Word; {保留}

nDescription: DWORD; {说明文本的长度} offDescription: DWORD; {说明文本的偏移量}

nPalEntries: DWORD; {调色板的元素数} szlDevice: TSize; {分辨率(像素)} szlMillimeters: TSize; {分辨率(毫米)} cbPixelFormat: DWORD; {} offPixelFormat: DWORD; {} bOpenGL: DWORD; {} end; 本例效果图: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); end; var

Form1: TForm1;

implementation

{$R *.dfm} var

HMetaFile: HENHMETAFILE; {EMF 文件句柄}

{建立带说明的 EMF 文件}

procedure TForm1.FormCreate(Sender: TObject); const

Path = 'C:\\Temp\\MyMeateFile.emf';

Description = 'ABCDE'; {当作 EMF 文件的说明} var

MetaFileDC: HDC; begin

{建立并写入说明}

MetaFileDC := CreateEnhMetaFile(0, PChar(Path), nil, PChar(Description)); {绘图}

Rectangle(MetaFileDC, 11, 11, 111, 111); {结束编辑、保存文件, 并返回文件句柄}

HMetaFile := CloseEnhMetaFile(MetaFileDC); {删除 DC}

DeleteObject(MetaFileDC); end;

{读取 EMF 文件头}