有两张图片,我想通过程序把他合并成一张,然后另存为一张新图
var
DestRect,SrcRect:TRect;
begin
DestRect:=Rect(0,0,Image2.Width,Image2.Height);
SrcRect :=DestRect;
Image2.Canvas.CopyMode:=cmSrcAnd;
Image2.Canvas.CopyRect(DestRect,Image1.Canvas,SrcRect);
Image1.Visible:=False;
end;
如果是jpg文件的话可以用
uses ...Jpeg;(加上jpeg单元)
......
procedure TForm1.Button1Click(Sender: TObject);
var
jp1, jp2, jp: TJPEGImage;
bmp_t, bmp: TBitmap;
begin
jp1 := TJPEGImage.Create;
jp2 := TJPEGImage.Create;
jp := TJPEGImage.Create;
try
jp1.LoadFromFile(''''C:/1.jpg'''');
jp2.LoadFromFile(''''C:/2.jpg'''');
bmp := TBitmap.Create;
bmp_t := TBitmap.Create;
try
bmp.Width := jp1.Width;
bmp.Height := jp1.Height jp2.Height;
bmp_t.Assign(jp1);
bmp.Canvas.Draw(0, 0, bmp_t);
bmp_t.Assign(jp2);
bmp.Canvas.Draw(0, jp1.Height, jp2);
jp.Assign(bmp);
jp.SaveToFile(''''C:/0.jpg'''');
finally
bmp.Free;
bmp_t.Free;
end;
finally
jp1.Free;
jp2.Free;
jp.Free;
end;
end;