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);
                }

    --

  • 相关阅读:
    linux command mktemp
    易经中时常会想起的句子
    判断NumLock键和CapsLock键是否被锁定
    获得虚拟键键码
    获取功能键
    捕获组合键
    模拟鼠标操作
    利用鼠标绘图
    使用鼠标拖放复制文本
    双击窗体是模拟键盘上的Tab键
  • 原文地址:https://www.cnblogs.com/runliuv/p/11911581.html
Copyright © 2011-2022 走看看