高分求助!急!关于TMetaFileCanvas(300分)

  • 主题发起人 主题发起人 Traveller
  • 开始时间 开始时间
T

Traveller

Unregistered / Unconfirmed
GUEST, unregistred user!
1.用TMetaFile.LoadFromXXX调入图片后,再调用TMetaFileCanvas.Create能不能保留原来的内容
2.为什么同样是小五号,在TMetaFileCanvas上画出来的字比在常规画布上画出来要大?
 
提,答出来可以再加分。
 
metafilecanvas的画布尺寸与所使用的create方法有关:
 
这个例子看看有用否?
代码:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    Timer1: TTimer;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    Wmf:TMetaFile;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
     Timer1.Enabled:=not Timer1.Enabled;
     if Timer1.Enabled then
        Button1.Caption:='Stop'
     else
         Button1.Caption:='Start';
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
     Wmf:=TMetaFile.Create;
     Wmf.Enhanced:=True;
     Randomize;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
   WmfCanvas:TMetafileCanvas;
   X,Y:integer;
begin
  
     Wmfcanvas:=TMetaFileCanvas.CreateWithComment(wmf,0,'Try','It Is a test!');
     try
      
        WmfCanvas.Brush.Color:=clWhite;
        WmfCanvas.FillRect(WmfCanvas.ClipRect);

         for x:=1 to 20 do
            for y:=1 to 20 do
            begin
                 WmfCanvas.MoveTo(22*(x+Random(2)),22*(Y+Random(2)));
                 WmfCanvas.Lineto(47*Y,47*X);
            end;
     finally
            WmfCanvas.Free;
     end;

       Image1.canvas.Draw(0,0,Wmf);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
     Wmf.SaveToFile(ExtractFilePath(Paramstr(0))+'test.emf');
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
   
     Wmf.LoadFromFile(ExtractFilePath(Paramstr(0))+'test.emf');
    
     Image1.Canvas.Draw(0,0,Wmf);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
     Image1.Align:=alClient;
     Image1.Align:=alNone;
     Image1.Picture.Bitmap.Width:=Image1.Width;
     Image1.Picture.Bitmap.Height:=Image1.Height;
     Image1.Canvas.StretchDraw(Image1.ClientRect,Wmf);
end;

end.
 
我找到原因了,原来是Image控件的问题,Image调入的时候不会按照原本的大小调入,而是产生一些偏差,直接Draw到Image的Canvas上则正常。
谢谢你的参与!
 
后退
顶部