如何将一个Metafile中已经绘制好的图形,Copy到另一个Metafile的指定位置?(90分)

  • 主题发起人 主题发起人 徐凤华
  • 开始时间 开始时间

徐凤华

Unregistered / Unconfirmed
GUEST, unregistred user!
我使用了CopyRect来实现两个MetafileCanvas的Copy操作,但是该操作在执行时既不报错,
也不会将所需要的内容Copy到另一个Metafile中,请问各位高手有何解决办法?
var
Metafile1, Metafile2: TMetafile;
MetafileCanvas1, Metafile2Canvas: TMetafileCanvas;
begin
Metafile1 := TMetafile.Create;
Metafile1.Width :=100;
Metafile1.Height := 100;
MetafileCanvas1 := TMetafileCanvas.Create(Metafile1, 0);
MetafileCanvas1.Brush.Color := clWhite;
MetafileCanvas1.FillRect(MetafileCanvas1.ClipRect);
MetafileCanvas1.TextOut(0,0,'daif;ajdkfai');

Metafile2 := TMetafile.Create;
Metafile2.Width := 100;
Metafile2.Height := 100;
Metafile2Canvas := TMetafileCanvas.Create(Metafile2, 0);
Metafile2Canvas.CopyRect(Metafile2Canvas.ClipRect, MetafileCanvas1, MetafileCanvas1.ClipRect);
Metafile2Canvas.Free;
MetafileCanvas1.Free;
Image1.Canvas.StretchDraw(Image1.Canvas.ClipRect, Metafile2);
end;
 
你完全可以先把MetaFile转化为BMP,然后拷贝,最后再转化回MetaFile.
至于怎么转化,搜索以前的帖子,或者给你 :

procedure WmfToBmp(FicheroWmf,FicheroBmp:string);
var
MetaFile:TMetafile;
Bmp:TBitmap;
begin
Metafile:=TMetaFile.create;
{Create a Temporal Bitmap}
Bmp:=TBitmap.create;
{Load the Metafile}
MetaFile.LoadFromFile(FicheroWmf);
{Draw the metafile in Bitmap's canvas}
with Bmp do
begin
Height:=Metafile.Height;
Width:=Metafile.Width;
Canvas.Draw(0,0,MetaFile);
{Save the BMP}
SaveToFile(FicheroBmp);
{Free BMP}
Free;
end;
{Free Metafile}
MetaFile.Free;
end;


procedure BmpToWmf (BmpFile,WmfFile:string);
var
MetaFile : TMetaFile;
MFCanvas : TMetaFileCanvas;
BMP : TBitmap;
begin
{Create temps}
MetaFile := TMetaFile.Create;
BMP := TBitmap.create;
BMP.LoadFromFile(BmpFile);
{Igualemos tama駉s}
{Equalizing sizes}
MetaFile.Height := BMP.Height;
MetaFile.Width := BMP.Width;
{Create a canvas for the Metafile}
MFCanvas:=TMetafileCanvas.Create(MetaFile, 0);
with MFCanvas do
begin
{Draw the BMP into canvas}
Draw(0, 0, BMP);
{Free the Canvas}
Free;
end;
{Free the BMP}
BMP.Free;
with MetaFile do
begin
{Save the Metafile}
SaveToFile(WmfFile);
{Free it...}
Free;
end;
end;
 
谢谢卷起千堆雪tyn,你帮我解决了一个大问题,谢谢!
分不多,敬请包涵。
 
接受答案了.
 
后退
顶部