GdiPlus[58]: 图像(十) IGPMetafile 特有的属性与方法


这包括:
//方法
IGPMetafile.GetMetafileHeader; { 获取 Metafile 的 MetafileHeader }
IGPMetafile.GetHEnhMetafile;   { 获取增强型 Metafile 的 Windows 句柄 }
IGPMetafile.PlayRecord();      { 播放单个图元文件记录 }

//属性
IGPMetafile.DownLevelRasterizationLimit; { 好像是控制纹理画刷的分辨率用的; 赋于 0 时则使用默认值. }

//还有
IGPGraphics.AddMetafileComment();     { 向当前 Metafile 添加注释 }
IGPGraphics.EnumerateMetafile();      { 枚举 Metafile 中的图形命令 }

IGPMetafile.GetMetafileHeader 获取文件信息, 得到一个 TGPMetafileHeader 结构对象:
TGPMetafileHeader.IsWmf;             { 是否是 Wmf 格式 }
TGPMetafileHeader.IsEmf;             { 是否是 Emf 格式 }
TGPMetafileHeader.IsEmfPlus;         { 是否是 Emf+ 格式 }
TGPMetafileHeader.IsEmfOrEmfPlus;    { 是否是 Emf 或 Emf+ 格式 }
TGPMetafileHeader.IsEmfPlusDual;     { 是否是 "双重" 增强型图元文件格式, 它同时支持 Emf 和 Emf+ }
TGPMetafileHeader.IsWmfPlaceable;    { 能否放置 Wmf }
TGPMetafileHeader.IsEmfPlusOnly;     { 是否只支持 Emf+ }
TGPMetafileHeader.IsDisplay;         { 是否与设备相关 }

TGPMetafileHeader.MetafileType;      { 类型 }
TGPMetafileHeader.MetafileSize;      { 大小; 以字节为单位 }
TGPMetafileHeader.Version;           { 版本号 }
TGPMetafileHeader.Bounds;            { 边界矩形 }
TGPMetafileHeader.DpiX;              { 水平分辨率; 以每英寸点数为单位 }
TGPMetafileHeader.DpiY;              { 垂直分辨率; 以每英寸点数为单位 }
TGPMetafileHeader.LogicalDpiX;       { 逻辑水平分辨率; 以每英寸点数为单位 }
TGPMetafileHeader.LogicalDpiY;       { 逻辑垂直分辨率; 以每英寸点数为单位 }
TGPMetafileHeader.EmfPlusFlags;      { Emf+ 标志 }
TGPMetafileHeader.WmfHeader;         { 获取 Wmf 文件头 }
TGPMetafileHeader.EmfHeader;         { 获取 Emf 文件头 }
TGPMetafileHeader.EmfPlusHeaderSize; { 获取 EmfHeader 的大小 }

简单显示(或叫回放)图元文件:

uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var
  Metafile: IGPMetafile;
  Graphics: IGPGraphics;
  Pt: TGPPointF;
begin
  Metafile := TGPMetafile.Create('C:\GdiPlusImg\SampleMetafile.emf');
  Graphics := TGPGraphics.Create(Handle);
  Graphics.DrawImage(Metafile, 10, 10);
end;

使用回调函数回放图元文件之一:

uses GdiPlus;

var Metafile: IGPMetafile;

function MetafileProc(RecordType: TEmfPlusRecordType; Flags, DataSize: UINT;
  Data: PByte; CallbackData: Pointer): BOOL; stdcall;
begin
  Metafile.PlayRecord(RecordType, Flags, DataSize, Data);
  Result := True;
end;

procedure TForm1.FormPaint(Sender: TObject);
var
//  Metafile: IGPMetafile;
  Graphics: IGPGraphics;
  Pt: TGPPointF;
begin
  Metafile := TGPMetafile.Create('C:\GdiPlusImg\SampleMetafile.emf');
  Graphics := TGPGraphics.Create(Handle);
  Pt.Initialize(10, 10);
  Graphics.EnumerateMetafile(Metafile, Pt, MetafileProc);
end;

使用回调函数回放图元文件之二(不使用全局变量):

uses GdiPlus;

function MetafileProc(RecordType: TEmfPlusRecordType; Flags, DataSize: UINT;
  Data: PByte; CallbackData: Pointer): BOOL; stdcall;
begin
  IGPMetafile(CallbackData).PlayRecord(RecordType, Flags, DataSize, Data);
  Result := True;
end;

procedure TForm1.FormPaint(Sender: TObject);
var
  Metafile: IGPMetafile;
  Graphics: IGPGraphics;
  Pt: TGPPointF;
begin
  Metafile := TGPMetafile.Create('C:\GdiPlusImg\SampleMetafile.emf');
  Graphics := TGPGraphics.Create(Handle);
  Pt.Initialize(10, 10);
  Graphics.EnumerateMetafile(Metafile, Pt, MetafileProc, Pointer(Metafile));
end;

获取图元文件中命令总数:

uses GdiPlus;

var Metafile: IGPMetafile;

function MetafileProc(RecordType: TEmfPlusRecordType; Flags, DataSize: UINT;
  Data: PByte; CallbackData: Pointer): BOOL; stdcall;
begin
  Inc(PInteger(CallbackData)^);
  Result := True;
end;

procedure TForm1.FormPaint(Sender: TObject);
var
  Graphics: IGPGraphics;
  n: Integer;
begin
  Metafile := TGPMetafile.Create('C:\GdiPlusImg\SampleMetafile.emf');
  Graphics := TGPGraphics.Create(Handle);
  n := 0;
  Graphics.EnumerateMetafile(Metafile, TGPPointF.Create(10,10), MetafileProc, @n);
  Text := IntToStr(n); { 13 }
end;
获取图元文件的命令类型列表:

uses GdiPlus;

var
  Metafile: IGPMetafile;
  List: TStrings;

procedure TForm1.FormCreate(Sender: TObject);
begin
  List := TStringList.Create;
  List.CommaText :=
    '66058=WmfRecordTypeSetTextJustification,'+
    '66059=WmfRecordTypeSetWindowOrg,'+
    '66060=WmfRecordTypeSetWindowExt,'+
    '66061=WmfRecordTypeSetViewportOrg,'+
    '66062=WmfRecordTypeSetViewportExt,'+
    '66063=WmfRecordTypeOffsetWindowOrg,'+
    '66576=WmfRecordTypeScaleWindowExt,'+
    '66065=WmfRecordTypeOffsetViewportOrg,'+
    '66578=WmfRecordTypeScaleViewportExt,'+
    '66067=WmfRecordTypeLineTo,'+
    '66068=WmfRecordTypeMoveTo,'+
    '66581=WmfRecordTypeExcludeClipRect,'+
    '66582=WmfRecordTypeIntersectClipRect,'+
    '67607=WmfRecordTypeArc,'+
    '66584=WmfRecordTypeEllipse,'+
    '66585=WmfRecordTypeFloodFill,'+
    '67610=WmfRecordTypePie,'+
    '66587=WmfRecordTypeRectangle,'+
    '67100=WmfRecordTypeRoundRect,'+
    '67101=WmfRecordTypePatBlt,'+
    '65566=WmfRecordTypeSaveDC,'+
    '66591=WmfRecordTypeSetPixel,'+
    '66080=WmfRecordTypeOffsetClipRgn,'+
    '66849=WmfRecordTypeTextOut,'+
    '67874=WmfRecordTypeBitBlt,'+
    '68387=WmfRecordTypeStretchBlt,'+
    '66340=WmfRecordTypePolygon,'+
    '66341=WmfRecordTypePolyline,'+
    '67110=WmfRecordTypeEscape,'+
    '65831=WmfRecordTypeRestoreDC,'+
    '66088=WmfRecordTypeFillRegion,'+
    '66601=WmfRecordTypeFrameRegion,'+
    '65834=WmfRecordTypeInvertRegion,'+
    '65835=WmfRecordTypePaintRegion,'+
    '65836=WmfRecordTypeSelectClipRegion,'+
    '65837=WmfRecordTypeSelectObject,'+
    '65838=WmfRecordTypeSetTextAlign,'+
    '67119=WmfRecordTypeDrawText,'+
    '67632=WmfRecordTypeChord,'+
    '66097=WmfRecordTypeSetMapperFlags,'+
    '68146=WmfRecordTypeExtTextOut,'+
    '68915=WmfRecordTypeSetDIBToDev,'+
    '66100=WmfRecordTypeSelectPalette,'+
    '65589=WmfRecordTypeRealizePalette,'+
    '66614=WmfRecordTypeAnimatePalette,'+
    '65591=WmfRecordTypeSetPalEntries,'+
    '66872=WmfRecordTypePolyPolygon,'+
    '65849=WmfRecordTypeResizePalette,'+
    '67904=WmfRecordTypeDIBBitBlt,'+
    '68417=WmfRecordTypeDIBStretchBlt,'+
    '65858=WmfRecordTypeDIBCreatePatternBrush,'+
    '69443=WmfRecordTypeStretchDIB,'+
    '66888=WmfRecordTypeExtFloodFill,'+
    '65865=WmfRecordTypeSetLayout,'+
    '65868=WmfRecordTypeResetDC,'+
    '65869=WmfRecordTypeStartDoc,'+
    '65615=WmfRecordTypeStartPage,'+
    '65616=WmfRecordTypeEndPage,'+
    '65618=WmfRecordTypeAbortDoc,'+
    '65630=WmfRecordTypeEndDoc,'+
    '66032=WmfRecordTypeDeleteObject,'+
    '65783=WmfRecordTypeCreatePalette,'+
    '65784=WmfRecordTypeCreateBrush,'+
    '66041=WmfRecordTypeCreatePatternBrush,'+
    '66298=WmfRecordTypeCreatePenIndirect,'+
    '66299=WmfRecordTypeCreateFontIndirect,'+
    '66300=WmfRecordTypeCreateBrushIndirect,'+
    '66301=WmfRecordTypeCreateBitmapIndirect,'+
    '67326=WmfRecordTypeCreateBitmap,'+
    '67327=WmfRecordTypeCreateRegion,'+
    '1=EmfRecordTypeHeader,'+
    '2=EmfRecordTypePolyBezier,'+
    '3=EmfRecordTypePolygon,'+
    '4=EmfRecordTypePolyline,'+
    '5=EmfRecordTypePolyBezierTo,'+
    '6=EmfRecordTypePolyLineTo,'+
    '7=EmfRecordTypePolyPolyline,'+
    '8=EmfRecordTypePolyPolygon,'+
    '9=EmfRecordTypeSetWindowExtEx,'+
    '10=EmfRecordTypeSetWindowOrgEx,'+
    '11=EmfRecordTypeSetViewportExtEx,'+
    '12=EmfRecordTypeSetViewportOrgEx,'+
    '13=EmfRecordTypeSetBrushOrgEx,'+
    '14=EmfRecordTypeEOF,'+
    '15=EmfRecordTypeSetPixelV,'+
    '16=EmfRecordTypeSetMapperFlags,'+
    '17=EmfRecordTypeSetMapMode,'+
    '18=EmfRecordTypeSetBkMode,'+
    '19=EmfRecordTypeSetPolyFillMode,'+
    '20=EmfRecordTypeSetROP2,'+
    '21=EmfRecordTypeSetStretchBltMode,'+
    '22=EmfRecordTypeSetTextAlign,'+
    '23=EmfRecordTypeSetColorAdjustment,'+
    '24=EmfRecordTypeSetTextColor,'+
    '25=EmfRecordTypeSetBkColor,'+
    '26=EmfRecordTypeOffsetClipRgn,'+
    '27=EmfRecordTypeMoveToEx,'+
    '28=EmfRecordTypeSetMetaRgn,'+
    '29=EmfRecordTypeExcludeClipRect,'+
    '30=EmfRecordTypeIntersectClipRect,'+
    '31=EmfRecordTypeScaleViewportExtEx,'+
    '32=EmfRecordTypeScaleWindowExtEx,'+
    '33=EmfRecordTypeSaveDC,'+
    '34=EmfRecordTypeRestoreDC,'+
    '35=EmfRecordTypeSetWorldTransform,'+
    '36=EmfRecordTypeModifyWorldTransform,'+
    '37=EmfRecordTypeSelectObject,'+
    '38=EmfRecordTypeCreatePen,'+
    '39=EmfRecordTypeCreateBrushIndirect,'+
    '40=EmfRecordTypeDeleteObject,'+
    '41=EmfRecordTypeAngleArc,'+
    '42=EmfRecordTypeEllipse,'+
    '43=EmfRecordTypeRectangle,'+
    '44=EmfRecordTypeRoundRect,'+
    '45=EmfRecordTypeArc,'+
    '46=EmfRecordTypeChord,'+
    '47=EmfRecordTypePie,'+
    '48=EmfRecordTypeSelectPalette,'+
    '49=EmfRecordTypeCreatePalette,'+
    '50=EmfRecordTypeSetPaletteEntries,'+
    '51=EmfRecordTypeResizePalette,'+
    '52=EmfRecordTypeRealizePalette,'+
    '53=EmfRecordTypeExtFloodFill,'+
    '54=EmfRecordTypeLineTo,'+
    '55=EmfRecordTypeArcTo,'+
    '56=EmfRecordTypePolyDraw,'+
    '57=EmfRecordTypeSetArcDirection,'+
    '58=EmfRecordTypeSetMiterLimit,'+
    '59=EmfRecordTypeBeginPath,'+
    '60=EmfRecordTypeEndPath,'+
    '61=EmfRecordTypeCloseFigure,'+
    '62=EmfRecordTypeFillPath,'+
    '63=EmfRecordTypeStrokeAndFillPath,'+
    '64=EmfRecordTypeStrokePath,'+
    '65=EmfRecordTypeFlattenPath,'+
    '66=EmfRecordTypeWidenPath,'+
    '67=EmfRecordTypeSelectClipPath,'+
    '68=EmfRecordTypeAbortPath,'+
    '69=EmfRecordTypeReserved_069,'+
    '70=EmfRecordTypeGdiComment,'+
    '71=EmfRecordTypeFillRgn,'+
    '72=EmfRecordTypeFrameRgn,'+
    '73=EmfRecordTypeInvertRgn,'+
    '74=EmfRecordTypePaintRgn,'+
    '75=EmfRecordTypeExtSelectClipRgn,'+
    '76=EmfRecordTypeBitBlt,'+
    '77=EmfRecordTypeStretchBlt,'+
    '78=EmfRecordTypeMaskBlt,'+
    '79=EmfRecordTypePlgBlt,'+
    '80=EmfRecordTypeSetDIBitsToDevice,'+
    '81=EmfRecordTypeStretchDIBits,'+
    '82=EmfRecordTypeExtCreateFontIndirect,'+
    '83=EmfRecordTypeExtTextOutA,'+
    '84=EmfRecordTypeExtTextOutW,'+
    '85=EmfRecordTypePolyBezier16,'+
    '86=EmfRecordTypePolygon16,'+
    '87=EmfRecordTypePolyline16,'+
    '88=EmfRecordTypePolyBezierTo16,'+
    '89=EmfRecordTypePolylineTo16,'+
    '90=EmfRecordTypePolyPolyline16,'+
    '91=EmfRecordTypePolyPolygon16,'+
    '92=EmfRecordTypePolyDraw16,'+
    '93=EmfRecordTypeCreateMonoBrush,'+
    '94=EmfRecordTypeCreateDIBPatternBrushPt,'+
    '95=EmfRecordTypeExtCreatePen,'+
    '96=EmfRecordTypePolyTextOutA,'+
    '97=EmfRecordTypePolyTextOutW,'+
    '98=EmfRecordTypeSetICMMode,'+
    '99=EmfRecordTypeCreateColorSpace,'+
    '100=EmfRecordTypeSetColorSpace,'+
    '101=EmfRecordTypeDeleteColorSpace,'+
    '102=EmfRecordTypeGLSRecord,'+
    '103=EmfRecordTypeGLSBoundedRecord,'+
    '104=EmfRecordTypePixelFormat,'+
    '105=EmfRecordTypeDrawEscape,'+
    '106=EmfRecordTypeExtEscape,'+
    '107=EmfRecordTypeStartDoc,'+
    '108=EmfRecordTypeSmallTextOut,'+
    '109=EmfRecordTypeForceUFIMapping,'+
    '110=EmfRecordTypeNamedEscape,'+
    '111=EmfRecordTypeColorCorrectPalette,'+
    '112=EmfRecordTypeSetICMProfileA,'+
    '113=EmfRecordTypeSetICMProfileW,'+
    '114=EmfRecordTypeAlphaBlend,'+
    '115=EmfRecordTypeSetLayout,'+
    '116=EmfRecordTypeTransparentBlt,'+
    '117=EmfRecordTypeReserved_117,'+
    '118=EmfRecordTypeGradientFill,'+
    '119=EmfRecordTypeSetLinkedUFIs,'+
    '120=EmfRecordTypeSetTextJustification,'+
    '121=EmfRecordTypeColorMatchToTargetW,'+
    '122=EmfRecordTypeCreateColorSpaceW,'+
    '16384=EmfPlusRecordTypeInvalid,'+
    '16385=EmfPlusRecordTypeHeader,'+
    '16386=EmfPlusRecordTypeEndOfFile,'+
    '16387=EmfPlusRecordTypeComment,'+
    '16388=EmfPlusRecordTypeGetDC,'+
    '16389=EmfPlusRecordTypeMultiFormatStart,'+
    '16390=EmfPlusRecordTypeMultiFormatSection,'+
    '16391=EmfPlusRecordTypeMultiFormatEnd,'+
    '16392=EmfPlusRecordTypeObject,'+
    '16393=EmfPlusRecordTypeClear,'+
    '16394=EmfPlusRecordTypeFillRects,'+
    '16395=EmfPlusRecordTypeDrawRects,'+
    '16396=EmfPlusRecordTypeFillPolygon,'+
    '16397=EmfPlusRecordTypeDrawLines,'+
    '16398=EmfPlusRecordTypeFillEllipse,'+
    '16399=EmfPlusRecordTypeDrawEllipse,'+
    '16400=EmfPlusRecordTypeFillPie,'+
    '16401=EmfPlusRecordTypeDrawPie,'+
    '16402=EmfPlusRecordTypeDrawArc,'+
    '16403=EmfPlusRecordTypeFillRegion,'+
    '16404=EmfPlusRecordTypeFillPath,'+
    '16405=EmfPlusRecordTypeDrawPath,'+
    '16406=EmfPlusRecordTypeFillClosedCurve,'+
    '16407=EmfPlusRecordTypeDrawClosedCurve,'+
    '16408=EmfPlusRecordTypeDrawCurve,'+
    '16409=EmfPlusRecordTypeDrawBeziers,'+
    '16410=EmfPlusRecordTypeDrawImage,'+
    '16411=EmfPlusRecordTypeDrawImagePoints,'+
    '16412=EmfPlusRecordTypeDrawString,'+
    '16413=EmfPlusRecordTypeSetRenderingOrigin,'+
    '16414=EmfPlusRecordTypeSetAntiAliasMode,'+
    '16415=EmfPlusRecordTypeSetTextRenderingHint,'+
    '16416=EmfPlusRecordTypeSetTextContrast,'+
    '16417=EmfPlusRecordTypeSetInterpolationMode,'+
    '16418=EmfPlusRecordTypeSetPixelOffsetMode,'+
    '16419=EmfPlusRecordTypeSetCompositingMode,'+
    '16420=EmfPlusRecordTypeSetCompositingQuality,'+
    '16421=EmfPlusRecordTypeSave,'+
    '16422=EmfPlusRecordTypeRestore,'+
    '16423=EmfPlusRecordTypeBeginContainer,'+
    '16424=EmfPlusRecordTypeBeginContainerNoParams,'+
    '16425=EmfPlusRecordTypeEndContainer,'+
    '16426=EmfPlusRecordTypeSetWorldTransform,'+
    '16427=EmfPlusRecordTypeResetWorldTransform,'+
    '16428=EmfPlusRecordTypeMultiplyWorldTransform,'+
    '16429=EmfPlusRecordTypeTranslateWorldTransform,'+
    '16430=EmfPlusRecordTypeScaleWorldTransform,'+
    '16431=EmfPlusRecordTypeRotateWorldTransform,'+
    '16432=EmfPlusRecordTypeSetPageTransform,'+
    '16433=EmfPlusRecordTypeResetClip,'+
    '16434=EmfPlusRecordTypeSetClipRect,'+
    '16435=EmfPlusRecordTypeSetClipPath,'+
    '16436=EmfPlusRecordTypeSetClipRegion,'+
    '16437=EmfPlusRecordTypeOffsetClip,'+
    '16438=EmfPlusRecordTypeDrawDriverString,'+
    '16439=EmfPlusRecordTypeStrokeFillPath,'+
    '16440=EmfPlusRecordTypeSerializableObject,'+
    '16441=EmfPlusRecordTypeSetTSGraphics,'+
    '16442=EmfPlusRecordTypeSetTSClip';
end;

function MetafileProc(RecordType: TEmfPlusRecordType; Flags, DataSize: UINT;
  Data: PByte; CallbackData: Pointer): BOOL; stdcall;
begin
  PString(CallbackData)^ := PString(CallbackData)^ + List.Values[IntToStr(Ord(RecordType))] + #13#10;
  Result := True;
end;

procedure TForm1.FormPaint(Sender: TObject);
var
  Graphics: IGPGraphics;
  str: string;
begin
  Metafile := TGPMetafile.Create('C:\GdiPlusImg\SampleMetafile.emf');
  Graphics := TGPGraphics.Create(Handle);
  Graphics.EnumerateMetafile(Metafile, TGPPointF.Create(10,10), MetafileProc, @str);
  ShowMessage(str);
{ 结果:
  EmfRecordTypeHeader
  EmfPlusRecordTypeHeader
  EmfPlusRecordTypeObject
  EmfPlusRecordTypeDrawRects
  EmfPlusRecordTypeDrawEllipse
  EmfPlusRecordTypeSetAntiAliasMode
  EmfPlusRecordTypeDrawEllipse
  EmfPlusRecordTypeSetTextRenderingHint
  EmfPlusRecordTypeRotateWorldTransform
  EmfPlusRecordTypeObject
  EmfPlusRecordTypeDrawString
  EmfPlusRecordTypeEndOfFile
  EmfRecordTypeEOF
}
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  List.Free;
end;

不回放其中的椭圆:

uses GdiPlus;

var Metafile: IGPMetafile;

function MetafileProc(RecordType: TEmfPlusRecordType; Flags, DataSize: UINT;
  Data: PByte; CallbackData: Pointer): BOOL; stdcall;
begin
  if RecordType <> EmfPlusRecordTypeDrawrEllipse then
  begin
    Metafile.PlayRecord(RecordType, Flags, DataSize, Data);
  end;
  Result := True;
end;

procedure TForm1.FormPaint(Sender: TObject);
var
  Graphics: IGPGraphics;
begin
  Metafile := TGPMetafile.Create('C:\GdiPlusImg\SampleMetafile.emf');
  Graphics := TGPGraphics.Create(Handle);
  Graphics.EnumerateMetafile(Metafile, TGPPointF.Create(10, 10), MetafileProc);
end;

转载于:https://www.cnblogs.com/del/archive/2009/12/31/1637172.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值