两张位图合成一张位图!(50分)

  • 主题发起人 主题发起人 傻子
  • 开始时间 开始时间

傻子

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么样用程序来实现两张位图合成一张位图呢。
 
使用CopyRect 方法:CopyRect(Dest: TRect; Canvas: TCanvas; Source: TRect)
例:把image1+image2=》image1
1.先把image1的大小设置成image1+image2的大小
2.image1.Canvas.CopyRect(DestRect; image2.Canvas, Rect (0, 0, image2.Width, image2.Height)
其中DestRect是image2在合并后image1的区域位置
 
DestRect
要怎么写啊。
 
TRect类型:
Left,Top,Right,Bottom四个参数分别表示区域的四个边界。
 
我知道那几个参数,我现在想粘在第一张图的后面,该怎么写啊。
 
你的意思是不是想做一张镂空图?
 
我是想把几张图,一张一张紧跟前面的一张
 
一直都调试不出来!
 
做类似相册一样的效果?
 
我给你一个详细的例子(并排,它们一样高)
image1.Width:=image1.Width+image2.width;

image1.Canvas.CopyRect(Rect(image1.Width,0,image2.Width,image2.Height); image2.Canvas, Rect (0, 0, image2.Width, image2.Height);

然后重复就行了

 
image1.Canvas.CopyRect(Rect(image1.Width,0,image1.Width,image1.Height); image2.Canvas, Rect (0, 0, image2.Width, image2.Height);
中应该是
image1.Canvas.CopyRect(Rect(image1.Width,0,image1.Width+image2.Width,image1.Height); image2.Canvas, Rect (0, 0, image2.Width, image2.Height);
 
Right和Left的数值一样了,所以无法复制
 
还是无法实现那个功能啊。
 
复制不到啊。
 
什么复制不到?
你的要求到底是什么?
你是不是想要将一连串的图片像胶片一样的显示出来。
 
是的呀。然后再保存为一个文件。
 
建议你直接绘制不要使用较多的image组件。
比如说要画 5 张图片,在窗口上有一个ImagePic组件
var
BmpImage: array[1..5] of Tbitmap;
IntWidth, IntN: Integer;
begin
IntWidth:=0;
for IntN:=1 to 5 do begin
ImagePic.Canvas.CopyRect(Rect(IntWidth,0,IntWidth+BmpImage[IntN].Width,BmpImage[IntN].Height), BmpImage.Canvas, Rect(0, 0, BmpImage[IntN].Width, BmpImage[IntN].Height));
IntWidth:=BmpImage[IntN].Width+IntWidth;
end;
end;
试一试,思想在代码中。准确率不一定,因为我是直接打出来的,没有经过测试。
BmpImage是要绘制图片的数组,类型为TBitmap。可以直接从bmp文件中提取。
 
ImagePic是Image组件,名字叫ImagePic
 
image1+image2->image3
我测试过,没问题
1.image1->image3
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
image3.Width:= image1.Width;
image3.Height:=image1.Height;
image3.Canvas.CopyRect(Rect (0, 0, image1.Width, image1.Height), image1.Canvas, Rect(0, 0, image1.Width, image1.Height));
end;
2.image1+image2->image3
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
image3.Width:= image1.Width+image2.width;
image3.Canvas.CopyRect(Rect(image1.Width, 0, image1.Width+image2.Width, image1.Height), image2.Canvas, Rect (0, 0, image2.Width, image2.Height));
end;
 
后退
顶部