C#简单的在图片上添加文字并保存

二话不说;直接上代码:


using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;


namespace 图片加水印
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
         static int x=0, y=0, h = 1368, w = 768;
        private void button1_Click(object sender, EventArgs e)
        {
            Graphics g = Graphics.FromImage(pictureBox1.Image);
            SolidBrush mybrush;
                mybrush = new SolidBrush(Color.Lime);  //设置默认画刷颜色
            Font myfont;
                myfont = new Font("黑体", 14);         //设置默认字体格式
            g.DrawString(textBox2.Text, myfont, mybrush, new Rectangle(x +500, y+50, w+500, h+50));
            pictureBox1.Refresh();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*";
            openFileDialog1.ShowDialog();
            if (openFileDialog1.FileName != null)
            {
                textBox1 .Text  = openFileDialog1.FileName;
                pictureBox1.Image = Image.FromFile(textBox1.Text);
            }
        }


        private void button3_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Filter = "JPG(*.jpg)|*.jpg|BMP(*.bmp)|*.bmp";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                pictureBox1.Image.Save(saveFileDialog1.FileName);
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            textBox2.Text  = Dns.GetHostEntry(Dns.GetHostName()).AddressList.FirstOrDefault<IPAddress>(a => a.AddressFamily.ToString().Equals("InterNetwork")).ToString();
            pictureBox1.Image = Image.FromFile(textBox1.Text);
        }
        }

}



  • 6
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值