zoukankan      html  css  js  c++  java
  • 图形技术(在图片中写入文字)


      string str;
           //在图片中绘制文字

           private void button1_Click(object sender, EventArgs e)
            {
                try
                {
                    Image myImage = System.Drawing.Image.FromFile(str);
                    Bitmap map = new Bitmap(myImage);
                    myImage.Dispose();
                    Graphics graphics = Graphics.FromImage(map);
                    graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
                    SolidBrush brush = new SolidBrush(Color.Red);
                    PointF P = new PointF(50, 50);
                    Font font = new Font(this.Font.Name, 40);
                    graphics.DrawString(textBox1.Text, font, brush, P);
                    map.Save(str.Substring(0, str.LastIndexOf("\\") + 1) + "new" + str.Substring(str.LastIndexOf("\\") + 1, str.LastIndexOf(".") - str.LastIndexOf("\\") - 1) + str.Substring(str.LastIndexOf("."), str.Length - str.LastIndexOf(".")), ImageFormat.Jpeg);
                    MessageBox.Show("写入成功");
                    font.Dispose();
                    graphics.Dispose();
                }
                catch { }
            }
            //选择图片
            private void button2_Click(object sender, EventArgs e)
            {
                try
                {
                    openFileDialog1.Filter = "JPG文件(*.jpg)|*.jpg";
                    openFileDialog1.ShowDialog();
                    str = openFileDialog1.FileName;
                    Image myImage = System.Drawing.Image.FromFile(str);
                    this.pictureBox1.Image = myImage;
                }
                catch { }
            }

  • 相关阅读:
    Python踩坑总结
    you-get下载酷我音乐付费歌曲
    Windows下python2和python3共存时pip失效(pip找不到)的解决办法
    正负混合排序,正数在前,负数在后
    用Python做窗口化滚动点名系统
    sublime3自定义快捷键运行python,支持input()函数
    python中字典,没键加键,有键操作其键对应的值,的思想
    python可变容器类型做函数参数的坑
    Ascii码 unicode码 utf-8编码 gbk编码的区别
    python文件操作各种模式和常用方法总结r r+ rb r+b
  • 原文地址:https://www.cnblogs.com/msAspnet/p/2097181.html
Copyright © 2011-2022 走看看