c#实现把汉字转为带田字格背景的jpg图片

所属分类: 软件编程 / C#教程 阅读数: 47
收藏 0 赞 0 分享

复制代码 代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
using System.IO;

namespace 文字图片生成程序
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
       static void checkdir()
        {
            string path="C:\\Users\\Default\\tran";
            if (!Directory.Exists(path))//判断目录是否存在
            {
                Directory.CreateDirectory(path);
            }
        }
        [STAThread]
        static void Main()
        {
            Program.checkdir();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());

        }


    }
    class Program1
    {
        private float hor=0.46f;//
        public static string src = null;
        public void setting(float[] z)
        {
            this.hor = z[5];//文字比例


            //线条比例
            //虚线比例
            //粗细比例
            //上下位置
            //左右位置
            //边框边界  bool
        }
        public void CreateImage(string lf,string content,int w,Color gezi,Color bg,Color ziti_a,Color ziti_b,string ziti,bool flag_b)
        {

            Font font;
            //创建一个位图对象
            Bitmap image = new Bitmap(w, w);
            //创建Graphics
            Graphics g = Graphics.FromImage(image);
            try
            {
                //清空图片背景颜色
                g.Clear(bg);
                if (!flag_b)
                    font = new Font(ziti, w * 0.65f);
                else
                    font = new Font(ziti, w * 0.65f, (FontStyle.Bold));
                System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), ziti_a, ziti_b, 4.0f, true);
                //画图片的边框线
                g.DrawRectangle(new Pen(gezi, w * 0.007f), w * 0.03f, w * 0.03f, w * 0.94f, w * 0.94f);
                //画虚线
                Pen pen1 = new Pen(gezi, w * 0.007f);
                pen1.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
                pen1.DashPattern = new float[] { w * 0.012f, w * 0.008f };
                g.DrawLine(pen1, w * 0.03f, w * 0.03f, w * 0.97f, w * 0.97f);
                g.DrawLine(pen1, w * 0.97f, w * 0.03f, w * 0.03f, w * 0.97f);
                g.DrawLine(pen1, w * 0.03f, w * 0.5f, w * 0.97f, w * 0.5f);
                g.DrawLine(pen1, w * 0.5f, w * 0.03f, w * 0.5f, w * 0.97f);
                StringFormat sf = new StringFormat();
                sf.Alignment = StringAlignment.Center;
                sf.LineAlignment = StringAlignment.Center;

                g.DrawString(content, font, brush, w*hor, w * 0.63f, sf);
                src = lf + content + ".jpg";

                image.Save(src);

              
            }
            finally
            {
                g.Dispose();
                image.Dispose();
            }
        }

    }

}

更多精彩内容其他人还在看

C#使用oledb读取excel表格内容到datatable的方法

这篇文章主要介绍了C#使用oledb读取excel表格内容到datatable的方法,涉及C#操作oledb及datatable的相关技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

C#使用oledb操作excel文件的方法

这篇文章主要介绍了C#使用oledb操作excel文件的方法,涉及C#中oledb操作excel的相关技巧,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享

C#使用IHttpModule接口修改http输出的方法

这篇文章主要介绍了C#使用IHttpModule接口修改http输出的方法,涉及C#操作IHttpModule接口的相关技巧,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享

C#给图片加水印的简单实现方法

这篇文章主要介绍了C#给图片加水印的简单实现方法,涉及C#操作图片的相关技巧,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享

C#生成随机数的方法小结

这篇文章主要介绍了C#生成随机数的方法,实例总结了C#生成随机数的相关技巧,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享

C#使用jQuery实现无刷新评论提交的方法

这篇文章主要介绍了C#使用jQuery实现无刷新评论提交的方法,涉及C#结合jQuery进行Ajax操作的相关技巧,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享

C#读取中文文件出现乱码的解决方法

这篇文章主要介绍了C#读取中文文件出现乱码的解决方法,涉及C#中文编码的操作技巧,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享

C#图像对比度调整的方法

这篇文章主要介绍了C#图像对比度调整的方法,涉及C#实现图像对比度操作的相关技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

C#图像灰度级拉伸的方法

这篇文章主要介绍了C#图像灰度级拉伸的方法,涉及C#灰度操作的相关技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

C#图像线性变换的方法

这篇文章主要介绍了C#图像线性变换的方法,涉及C#操作图像线性变换的相关技巧,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多