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

    如下是自己曾经编写过的代码,放到这个地方,免的以后自己在去查看怎么编写这样的代码.....
    :图片上写字,并设置背景色
         #region 创建树节点的图标
            /// <summary>
            /// 创建树节点的图标
            /// </summary>
            /// <param name="txt"></param>
            /// <param name="txtColor"></param>
            /// <returns></returns>
            private Bitmap CreateNodeImg(string txt, Color txtColor)
            {
                if (txtColor == Color.Transparent)
                    txtColor = Color.Black;
                Bitmap newBitMap = new Bitmap(12, 14);
                Graphics g = Graphics.FromImage(newBitMap);
                if (txtColor != Color.Black)
                {
                    g.Clear(txtColor);//背景色
                }
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                FontFamily fm = new FontFamily("Arial");
                Font font = new Font(fm, 12, FontStyle.Regular, GraphicsUnit.Pixel);
                SolidBrush sb = new SolidBrush(Color.Black);
                g.DrawString(txt, font, sb, new PointF(0, 0));
                g.Dispose();
                return newBitMap;
            }
     合并图片
      #region 合并图片
            /// <summary>
            /// 合并图片
            /// </summary>
            /// <param name="maps"></param>
            /// <returns></returns>
            private Bitmap MergerImg(params Bitmap[] maps)
            {
                int i = maps.Length;
                if (i == 0)
                    throw new Exception("图片数不能够为0");
                //创建要显示的图片对象,根据参数的个数设置宽度
                Bitmap backgroudImg = new Bitmap(i * 12, 16);
                Graphics g = Graphics.FromImage(backgroudImg);
                //清除画布,背景设置为白色
                g.Clear(System.Drawing.Color.White);
                for (int j = 0; j < i; j++)
                {
                    g.DrawImage(maps[j], j * 11, 0, maps[j].Width, maps[j].Height);
                }
                g.Dispose();
                return backgroudImg;
            }
            #endregion
            #region 合并图片
            /// <summary>
            /// 合并图片
            /// </summary>
            /// <param name="bitMapDic"></param>
            /// <returns></returns>
            private Bitmap MergerImg(Dictionary<string, Bitmap> bitMapDic)
            {
                if (bitMapDic == null || bitMapDic.Count == 0)
                    throw new Exception("图片数不能够为0");
                //创建要显示的图片对象,根据参数的个数设置宽度
                Bitmap backgroudImg = new Bitmap(bitMapDic.Count * 12, 16);
                Graphics g = Graphics.FromImage(backgroudImg);
                //清除画布,背景设置为白色
                g.Clear(System.Drawing.Color.White);
                int j = 0;
                foreach (KeyValuePair<string, Bitmap> entry in bitMapDic)
                {
                    Bitmap map = entry.Value;
                    g.DrawImage(map, j * 11, 0, map.Width, map.Height);
                    j++;
                }
                g.Dispose();
                return backgroudImg;
            }
     
                //合并图片还可以:
                //int i = maps.Length;
                //if (i == 0)
                //    throw new Exception("图片数不能够为0");
                ////创建要显示的图片对象,根据参数的个数设置宽度
                //Bitmap backgroudImg = new Bitmap(i * 16, 16);
                //Graphics g = Graphics.FromImage(backgroudImg);
                ////清除画布,背景设置为白色
                //g.Clear(System.Drawing.Color.White);
                //g.DrawImageUnscaled(maps[0], 0, 0);
                //g.DrawImageUnscaled(maps[1], maps[0].Width, 0);
                //g.Dispose();
                //return backgroudImg;
  • 相关阅读:
    Cross-Site Scripting(XSS)简介
    nginx查看安装了哪些模块
    Win7系统修改hosts文件不能保存的解决方法
    firefox怎么修改tls协议号
    在Nginx中部署基于IP的虚拟主机
    openssl生成ssl证书
    给kali linux2.0装一个中文输入法
    tenda u1 usb wireless device install driver for kali linux kernal Debian 4.3.3-7kali2 (2016-01-27) x86_64 GNU/Linux
    python2.7.x的字符串编码到底什么鬼?(中文和英文的处理)
    fswatch rsync配置使用 rsync 传输大量细小文件
  • 原文地址:https://www.cnblogs.com/szytwo/p/2818944.html
Copyright © 2011-2022 走看看