编程技术 · 2018 年 12 月 18 日 0

C#图片拼接(全景图片的实现)

关于图片拼接,我们可以调用Graphics.DrawImage里面的接口实现,具体代码如下:

 private static Image JoinImage(Image Img1, Image Img2)//实现左右拼接图片
        {
            int imgHeight = 0, imgWidth = 0;
            imgWidth = Img1.Width + Img2.Width;
            imgHeight = Math.Max(Img1.Height, Img2.Height);
            Bitmap joinedBitmap = new Bitmap(imgWidth, imgHeight);
            Graphics graph = Graphics.FromImage(joinedBitmap);
            graph.DrawImage(Img1, 0, 0, Img1.Width, Img1.Height);
            graph.DrawImage(Img2, Img1.Width, 0, Img2.Width, Img2.Height);
            return joinedBitmap;
        }