合并两个影像创建于C#.NET一个单一的形象 [英] Merge two images to create a single image in C#.Net

查看:130
本文介绍了合并两个影像创建于C#.NET一个单一的形象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,其中我需要合并产生到使用C#.NET单个图像两种不同PNG / JPEG图像。将有源图像上定义的,其中我需要插入另一个图像的特定位置。任何人都可以提出一些链接?

I have a requirement wherein I need to merge two different png/jpeg images resulting into a single image using C#.Net. There will be a particular location defined on the source image wherein I need to insert another image. Can anybody suggest some links ?

推荐答案

这个方法合并两个图像之一,你可以修改code,以满足您的需求,其他的顶部:

This method merge two images one in the top of the other you can modify the code to meet for your needs:

    public static Bitmap MergeTwoImages(Image firstImage, Image secondImage)
    {
        if (firstImage == null)
        {
            throw new ArgumentNullException("firstImage");
        }

        if (secondImage == null)
        {
            throw new ArgumentNullException("secondImage");
        }

        int outputImageWidth = firstImage.Width > secondImage.Width ? firstImage.Width : secondImage.Width;

        int outputImageHeight = firstImage.Height + secondImage.Height + 1;

        Bitmap outputImage = new Bitmap(outputImageWidth, outputImageHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

        using (Graphics graphics = Graphics.FromImage(outputImage))
        {
            graphics.DrawImage(firstImage, new Rectangle(new Point(), firstImage.Size),
                new Rectangle(new Point(), firstImage.Size), GraphicsUnit.Pixel);
            graphics.DrawImage(secondImage, new Rectangle(new Point(0, firstImage.Height + 1), secondImage.Size),
                new Rectangle(new Point(), secondImage.Size), GraphicsUnit.Pixel);
        }

        return outputImage;
    }

这篇关于合并两个影像创建于C#.NET一个单一的形象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆