zoukankan      html  css  js  c++  java
  • 图片水印

    水印文字

    //加水印
            private void button1_Click(object sender, EventArgs e)
            {
                DialogResult dia = openFileDialog1.ShowDialog();
                if (dia == DialogResult.OK)
                {
                    string text = txtFont.Text;//水印内容
                    //需要操作的图片路径
                    string path = openFileDialog1.FileName;
                    //图片对象的创建
                    Bitmap img = new Bitmap(path);
                    //画布工具
                    Graphics g = Graphics.FromImage(img);
                    Font f = new Font("微软雅黑",20);
                    Brush b = new SolidBrush(Color.Red);
                    int x = img.Width / 2;
                    int y = img.Height / 2;
                    g.DrawString(text,f,b,x,y);
                    string xinPath = path.Substring(0,path.LastIndexOf(".")+1)+".jpg";
                    img.Save(xinPath,ImageFormat.Jpeg);
                    MessageBox.Show("加水完成");
                }
            }

    水印图片

    public Form1()
            {
                InitializeComponent();
            }
            string waterImg;//水印图
            string mainImg;//主图
            //水印图
            private void button1_Click(object sender, EventArgs e)
            {
                DialogResult dia = openFileDialog1.ShowDialog();
                if (dia == DialogResult.OK)
                {
                    waterImg = openFileDialog1.FileName;
                    txtWater.Text = openFileDialog1.FileName;
                }
            }
            //主图
            private void button2_Click(object sender, EventArgs e)
            {
                DialogResult dia = openFileDialog1.ShowDialog();
                if (dia == DialogResult.OK)
                {
                    mainImg = openFileDialog1.FileName;
                    txtMain.Text = openFileDialog1.FileName;
                }
            }
            //合并图片
            private void button3_Click(object sender, EventArgs e)
            {
                //主图
                Bitmap main = new Bitmap(mainImg);
                Image image = Image.FromFile(waterImg);
                Bitmap water = new Bitmap(image,100,100);//水印
                Graphics g = Graphics.FromImage(main);
                g.DrawImage(water,main.Width-water.Width,main.Height-water.Height);
    
                string path = mainImg.Substring(0,mainImg.LastIndexOf(".")+1)+".jpg";
                main.Save(path,ImageFormat.Jpeg);
                MessageBox.Show("合成成功");
            }
  • 相关阅读:
    解决mac启动springboot项目很慢的问题
    Oracle如何创建索引、删除索引、查询索引
    查看Oracle索引是否被使用或者有效
    Mysql创建、使用循环函数
    处理idea加载不到Spring的xml或者properties配置文件
    UML常用图、常见关系、设计模式
    设置文本框能够滚动
    MFC中的ID命名规则
    MFC应用中如何触发ON_MESSAGE
    使用MFC创建一个可视化程序
  • 原文地址:https://www.cnblogs.com/dujian123/p/10594376.html
Copyright © 2011-2022 走看看