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

 更新时间:2014年03月03日 09:23:19   作者:  
这篇文章主要介绍了c#实现把汉字转为带田字格背景的jpg图片示例,需要的朋友可以参考下

复制代码 代码如下:

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# Winfom 中ListBox的简单用法详解

    C# Winfom 中ListBox的简单用法详解

    这篇文章主要介绍了C# Winfom 中ListBox的简单用法详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-12-12
  • 详解C# 枚举高级用法之Description

    详解C# 枚举高级用法之Description

    这篇文章主要介绍了C# 枚举高级用法之Description,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-02-02
  • 使用aspose.word 第三方的插件实现导出word

    使用aspose.word 第三方的插件实现导出word

    本文给大家分享的是一个使用使用aspose.word 第三方的插件实现导出word的实例,十分的实用,有需要的小伙伴可以参考下。
    2015-06-06
  • c# 通过代码开启或关闭防火墙

    c# 通过代码开启或关闭防火墙

    这篇文章主要介绍了c# 通过代码开启或关闭防火墙的示例,帮助大家更好的理解和使用c#,感兴趣的朋友可以了解下
    2020-10-10
  • C#难点逐个击破(9):类型转换

    C#难点逐个击破(9):类型转换

    类型之间的转换可以分为隐式转换与显式转换,如int类型可直接转换为long类型。
    2010-02-02
  • C#连接Oracle数据库使用Oracle.ManagedDataAccess.dll

    C#连接Oracle数据库使用Oracle.ManagedDataAccess.dll

    这篇文章主要介绍了C#使用Oracle.ManagedDataAccess.dll的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-11-11
  • C#图片添加水印的实现代码

    C#图片添加水印的实现代码

    这篇文章主要为大家详细介绍了C#给图片添加水印的实现代码,不仅可以为图片加文字水印,还可以判断是否是图片文件,感兴趣的小伙伴们可以参考一下
    2016-02-02
  • WPF拖动DataGrid滚动条时内容混乱的解决方法

    WPF拖动DataGrid滚动条时内容混乱的解决方法

    这篇文章主要介绍了WPF拖动DataGrid滚动条时内容混乱的解决方法
    2016-10-10
  • unity实现文字滚动效果

    unity实现文字滚动效果

    这篇文章主要为大家详细介绍了unity实现文字滚动效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-02-02
  • C#服务生命周期:Singleton、Scoped、Transient用法及说明

    C#服务生命周期:Singleton、Scoped、Transient用法及说明

    文章介绍了三种服务生命周期:单例、作用域和瞬态,并讨论了如何在ASP.NETCore中使用这些生命周期管理服务,单例在应用程序生命周期中只有一个实例,作用域在每个请求中创建一个新实例,瞬态每次请求时创建一个新实例
    2025-01-01

最新评论