zoukankan      html  css  js  c++  java
  • C#.NET 合并图片

    引用:https://www.cnblogs.com/stulzq/p/6137715.html

    util:

    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    
    namespace DotNet合并图片.Utils
    {
       public static class ImageUtil
        {
    
            /// <summary>  
            /// 合并图片,默认是垂直合并,图1在上,图2在下。
            /// </summary>  
            /// <param name="imgBack"></param>  
            /// <param name="img"></param>  
            /// <returns></returns>  
            public static Bitmap CombinImage(Image imgBack, Image img, int xDeviation = 0, int yDeviation = 0)
            {
    
                Bitmap bmp = new Bitmap(imgBack.Width, imgBack.Height + img.Height);
    
                Graphics g = Graphics.FromImage(bmp);
                g.Clear(Color.White);
                g.DrawImage(imgBack, 0, 0, imgBack.Width, imgBack.Height); //g.DrawImage(imgBack, 0, 0, 相框宽, 相框高);     
    
                //g.FillRectangle(System.Drawing.Brushes.White, imgBack.Width / 2 - img.Width / 2 - 1, imgBack.Width / 2 - img.Width / 2 - 1,1,1);//相片四周刷一层黑色边框    
    
                //g.DrawImage(img, 照片与相框的左边距, 照片与相框的上边距, 照片宽, 照片高);    
    
                g.DrawImage(img, imgBack.Width / 2 - img.Width / 2 + xDeviation, imgBack.Height + yDeviation, img.Width, img.Height);
                GC.Collect();
                return bmp;
            }
    
    
        }
    }

    使用:

    try
                {
                    string iamge1FullName = Path.Combine(Application.StartupPath, "1.png");
                    string iamge2FullName = Path.Combine(Application.StartupPath, "2.png");
                    Image img1 = Image.FromFile(iamge1FullName);
                    Image img2 = Image.FromFile(iamge2FullName);
    
    
                    string iamgeAllFullName = Path.Combine(Application.StartupPath, "all.png");
    
                    Bitmap bmAll = DotNet合并图片.Utils.ImageUtil.CombinImage(img1, img2);
    
                    bmAll.Save(iamgeAllFullName, ImageFormat.Png);
    
                    MessageBox.Show("完成!");
    
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

    --

  • 相关阅读:
    完整的UED流程
    curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
    部署方案模板
    商城项目合作
    架构师分类
    k8s视图
    虚拟化通信技术
    AxureRP8 实现时间功能
    在AxureRP8中实现广告文字滚动效果
    获取当前网络中的电脑数目及MAC-通过MAC查找IP-通过IP查询机器名
  • 原文地址:https://www.cnblogs.com/runliuv/p/11911581.html
Copyright © 2011-2022 走看看