关于图元图像拷贝的问题(100分)

J

jsj971

Unregistered / Unconfirmed
GUEST, unregistred user!
两个图元对象,同时在一个窗体上
现在要在一个图元拷贝它的一部分图像到另一个图元上,怎么实现?(用图元是为了拷贝后的图像可以矢量放大)

我的代码如下,怎么不行啊?

加二个image控件及一个按钮
var a,b:tmetafile;
ac,bc:tmetafilecanvas;
arect:trect;
begin
a:=tmetafile.Create;
a.Width :=10;
a.Height :=10;
b:=tmetafile.Create;
b.Width :=50;
b.Height :=50;
ac:=tmetafilecanvas.Create(a,0);

bc:=tmetafilecanvas.Create(b,0);
ac.LineTo(100,100);

arect:=rect(0,0,100,100);

bc.CopyRect(arect,ac,arect);

ac.Free;
image1.Canvas.Draw(0,0,a);
a.free;

bc.Free;
image2.Canvas.Draw(0,0,b);
b.free;
end;
请大侠帮忙给个代码或是原理或是方法或是函数或是答案吧...
 
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Image1: TImage;
Image2: TImage;
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
Image1.Picture.Bitmap := TBitmap.Create;
with Image1.Picture.Bitmap do
begin
Width := 100;
Height := 100;
Canvas.TextOut(1, 1, 'A');

end;

Image2.Width := 2*Image1.Width;
Image2.Height :=2* Image1.Height;
Image2.Picture.Bitmap := TBitmap.Create;

with Image2.Picture.Bitmap do
begin
Width := Image2.Width;
Height := Image2.Height;

// BitBlt(Canvas.Handle,0,0, Width,Height, Image1.Picture.Bitmap.Canvas.Handle , )

Canvas.CopyRect(rect(0, 0, Width, Height), Image1.Picture.Bitmap.Canvas, rect(0, 0, 100, 100))
end;

end;

end.


object Form1: TForm1
Left = 77
Top = 119
Width = 544
Height = 375
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Image1: TImage
Left = 56
Top = 32
Width = 105
Height = 105
end
object Image2: TImage
Left = 280
Top = 24
Width = 201
Height = 225
end
object BitBtn1: TBitBtn
Left = 184
Top = 192
Width = 75
Height = 25
Caption = 'BitBtn1'
TabOrder = 0
OnClick = BitBtn1Click
end
end

 
这样子拷贝的只是位图,像这样一放大就会失真,例子里就是这样子
请哪位高手另赐高招
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
583
import
I
I
回复
0
查看
627
import
I
顶部