• 图片水印


    水印文字

    //加水印
            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("合成成功");
            }
  • 相关阅读:
    如何将自己的做的Silverlight项目发布到博客园中
    JS对当前时间的操作
    rt—移植笔记1
    rt—移植笔记2(Lwip)
    RabbitMQ一:Windows安装RabbitMQ Server
    Redis实现分布式锁
    ssh前后台交互, list传输到前后展示,table传输到台数据!!!。ssh对象传输
    Delphi中API编程编译实现
    struts2简单遍历Map
    phonegap file操作
  • 原文地址:https://www.cnblogs.com/dujian123/p/10594376.html
Copyright © 2020-2023  润新知