The Delphi Bug List

Entry No.
594
VCL - Graphics - Graphics - Metafiles
Problem with size of Windows Metafile
1.02 2.01 3.0 3.01 3.02 4.0 4.01 4.02 4.03 5.0 5.01 6.0 6.01 6.02 Kylix 1.0
UnknownUnknownUnknownUnknownUnknownExistsExistsExistsExistsExistsExistsExistsExistsExistsN/A
Description
Reported by Benny Markström; checked by Reinier Sterkenburg
The following code does not work in Windows NT or Windows 2000.
I open a WMF file to make some changes in it and after that I save the file. The picture size is the same but the content is zoomed in!!!
The same code and exe file works in Windows 95/98.
Here the the maincode in Unit1.pas :
procedure TForm1.Button2Click(Sender: TObject);
var
  MyMetaFile:TMetaFile;
  Meta:TMetaFileCanvas;
begin
  if not Image1.Picture.Metafile.Empty then begin
    MyMetaFile := TMetaFile.Create;
    MyMetaFile.LoadFromFile(OpenPictureDialog1.FileName );

    Meta:=TMetafileCanvas.Create(MyMetaFile,0);
    Meta.Draw(0,0,MyMetaFile);
    (*
    Do something ...
       Meta.TextOut(10,10,'HELLO');
    *)
    Meta.Free;
    Image2.Picture.Graphic:=MyMetaFile;
    MyMetaFile.Free;
    Image2.Picture.SaveToFile('NewFile.WMF');
  end;
end;
The whole (small) test project is in Test594.zip
User-contributed comments
Michael Schümann
31 Oct 2001  03:12 PM GMT
The "expanding universe error" is found in NT4.0 too. The size of the old metafileCanvas shrinks while using Draw or StretchDraw, the new Canvas is correct in size.

Has anyone an idea about it or solution ?
schuemann@uke.uni-hamburg.de

Try the added code as an example:

var
 MF: tMetaFile;
 i,j    : integer;
 MyRect : TRect;
// AMC,
 BMC    : tMetaFileCanvas;
begin
MF:= tMetaFile.create;
with MF do begin
 mmWidth:=10000;
 mmHeight:=12000;
 with TMetaFileCanvas.CreateWithComment(MF,0,'Misc-Test','Text') do free;
 with TMetaFileCanvas.Create(MF,0) do try
  Draw(0,0,MF);
  for j:=1 to 100 do
    pixels[random(MF.width),random(MF.Height)]:=clBlue;
  MoveTo(0,0);
  LineTo(MF.Width,MF.Height);
finally
 free;
end;
  MetaMain.Image1.width:=MF.width;     // show it somewhere
  MetaMain.Image1.height:=MF.height;   // in an defined image
  MetaMain.Image1.Canvas.Draw(0,0,MF);
  MetaMain.Image1.Refresh;

MyRect:=Rect(0,0,MF.width,MF.height);  // is Draw the problem
                                       // or performs StretchDrw  better ??
for i:=1 to 50 do                      // here the identity test for the
begin                                  // Metafile size starts

  BMC:=TMetaFileCanvas.Create(MF,0);
  with  BMC do try
   Draw(0,0,MF);
// StretchDraw(MyRect,MF); // does the same problem
   MoveTo(0,0);LineTo(MF.width,MF.Height);
  finally
   free;
  end;

  MetaMain.Image1.width:=MF.width;    // show it again 
  MetaMain.Image1.height:=MF.height;  // and wonder !!!
  MetaMain.Image1.Canvas.Draw(0,0,MF);
  MetaMain.Image1.Refresh;
 end;
end;
MF.SaveToFile('TT.wmf');
MF.Free;
Latest update of this entry: 2002-04-09

Post a comment on this bug


Index page
Delphi Bug List home page
The Delphi Bug Lists are presently maintained by Jordan Russell, who has taken over this task from Reinier Sterkenburg since August 2000.
All feedback is appreciated. See also the feedback section of the Delphi Bug List home page.