zoukankan      html  css  js  c++  java
  • C#把多个图片合并成一张图片。

      private void button7_Click(object sender, EventArgs e)
            {
               //把2个图片合并到一个图片中
                //文件路径
                string fs = Application.StartupPath +"\PIC\";
                //不存在文件进行创建
                if (!System.IO.Directory.Exists(fs)) System.IO.Directory.CreateDirectory(fs);
                //存储到pic文件夹中文件
                ocx.PadFileSaveAs(fs, 22, 1);
                //获取到pic下面的jpg图片
                string[] rs = System.IO.Directory.GetFiles(fs, "*.jpg");
                //最大宽度和高度
                int maL = 0, totalH = 0;
    
                //循环遍历获取文件的最大宽度与总高度
                for (int i = 0; i < rs.Length; i++)
                {
                    Image image = Image.FromStream(new System.IO.MemoryStream(File.ReadAllBytes(rs[i])));
                    if (image.Width > maL) maL = image.Width;
                    totalH = totalH +  image.Height + 5;
                }
                if (totalH == 0 || maL == 0) return;
                Bitmap map = new Bitmap(maL, totalH);//定义画布
                Graphics g = Graphics.FromImage(map);//定义画笔
                g.Clear(Color.White);//把画布更改为白色
                int y=0;//y轴坐标
                for (int i = 0; i < rs.Length; i++)
                {
                    Image image = Image.FromStream(new System.IO.MemoryStream(File.ReadAllBytes(rs[i])));
                    g.DrawImage(image, new Point(0, y));
                    y = y + image.Height + 5;//y的告诉 5是为了让画布有个缝隙
                }
                //把合并的图片进行保存为jpg格式
                map.Save(Application.StartupPath + "\1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
                for (int i = 0; i < rs.Length; i++)
                {
                    //删除原先的2个jpg图片
                    File.Delete(rs[i]);
                }
    
            }

    效果图:

  • 相关阅读:
    操作系统:中断和异常
    操作系统
    编程:判断一个点是否在三角形内部
    python 多态
    python super()函数:调用父类的构造方法
    python 继承机制(子类化内置类型)
    python 父类方法重写
    python 继承机制
    python 封装底层实现原理
    python 类的封装
  • 原文地址:https://www.cnblogs.com/smile-wei/p/14296531.html
Copyright © 2011-2022 走看看