Delphi如何创建并绘制EMF图形文件

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    PaintBox1: TPaintBox;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
    MetaFile : TMetaFile;
    MFCanvas : TMetaFileCanvas;
    BMP : TBitmap;
    LDC : HDC;
begin
  MetaFile := TMetaFile.Create;
  MetaFile.Height := 100;
  MetaFile.Width := 100;
  LDC := GetDC(0);
  MFCanvas:=TMetafileCanvas.Create(MetaFile, LDC);
  with MFCanvas do
  begin
    Pen.Color := clRed;
    Pen.Width := 5;
    MoveTo(0,0);
    LineTo(100,100);
    Free;
  end;
  Self.PaintBox1.Canvas.Draw(0,0,MetaFile);
  with MetaFile do
  begin
    SaveToFile('c:\未命名2.EMF');     {Free it...}
    Free;
  end;
  end;
end.

本程序在Delphi 2010上测试过,没有问题。

猜你喜欢

转载自www.cnblogs.com/China3S/p/9692331.html
EMF