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("合成成功");
            }
  • 相关阅读:
    给数组赋值nan
    loc和iloc的区别
    爬虫26-部署crawl爬虫
    爬虫25-scrapy框架详解
    爬虫24-scrapy框架部署
    爬虫23-验证码识别
    爬虫22-使用selenium爬取信息
    爬虫21-selenium用法
    爬虫20-浏览器自动运行简单方法
    爬虫19-线程生产者和消费者以及队列
  • 原文地址:https://www.cnblogs.com/dujian123/p/10594376.html
Copyright © 2011-2022 走看看