有一个最简单的办法做到拼接,对吧,你的意思是拼接。
我下面的代码是两张一摸一样的图片,图片1、2,大小一致,然后横向拼接到一起。
思路是:
1、获取图片1的大小信息
2、创建一个空白RasterImage,这个对象的尺寸是图片1宽度的两倍。
3、在这个空白图片的左侧加载图片1,右侧加载图片2
4、保存这个空白图片对象,就会得到拼接到一起的图片3.
示例代码:
CodecsImageInfo info = codecs.GetInformation(strFile1, true);
RasterImage img = new RasterImage(RasterMemoryFlags.Conventional, info.Width * 2, info.Height, info.BitsPerPixel, info.Order, info.ViewPerspective, null, IntPtr.Zero, 0);
RasterImage image1 = codecs.Load(strFile1);
RasterImage image2 = codecs.Load(strFile2);
CombineCommand command = new CombineCommand();
command.SourceImage = image1;
// the rectangle that represents the affected area of the destination image.
command.DestinationRectangle = new LeadRect(0, 0, image1.Width, image1.Height);
// The source point, which represents the source point of the source image which is to be combined.
command.SourcePoint = new LeadPoint(0, 0);
// the operations that will be performed to produce the result, and the channel that will be used to achieve this result.
command.Flags = CombineCommandFlags.OperationAdd ;
command.Run(img);
command.SourceImage = image2;
// the rectangle that represents the affected area of the destination image.
command.DestinationRectangle = new LeadRect(image1.Width, 0, image1.Width, image1.Height);
// The source point, which represents the source point of the source image which is to be combined.
command.SourcePoint = new LeadPoint(0, 0);
// the operations that will be performed to produce the result, and the channel that will be used to achieve this result.
command.Flags = CombineCommandFlags.OperationAdd;
command.Run(img);
this.pictureBox3.Image = RasterImageConverter.ChangeToImage(img, Leadtools.Drawing.ChangeToImageOptions.ForceChange); |