加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 09:55:05 所属栏目:大数据 来源:网络整理
导读: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 {
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
  try
    MetaFile := TMetaFile.Create;
    MetaFile.Height := Self.PaintBox1.Height;
    MetaFile.Width := Self.PaintBox1.Width;
    try
      LDC := GetDC(0);
      MFCanvas:=TMetafileCanvas.Create(MetaFile,LDC);
      MFCanvas.Pen.Color := clRed;
      MFCanvas.Pen.Width := 5;
      MFCanvas.Brush.Color :=clBlue;
      MFCanvas.MoveTo(0,0);
      MFCanvas.Rectangle(0,0,Self.PaintBox1.Width,Self.PaintBox1.Height);
      MFCanvas.LineTo(Self.PaintBox1.Width,Self.PaintBox1.Height);
    finally
       MFCanvas.Free;
       ReleaseDC(0,LDC);
    end;
    Self.PaintBox1.Canvas.Draw(0,MetaFile);
    MetaFile.SaveToFile(c:未命名2.EMF);
  finally
    MetaFile.Free;
  end;
  end;
end.

?

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读