c#實(shí)現(xiàn)把漢字轉(zhuǎn)為帶田字格背景的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>
/// 應(yīng)用程序的主入口點(diǎn)。
/// </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];//文字比例
//線條比例
//虛線比例
//粗細(xì)比例
//上下位置
//左右位置
//邊框邊界 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;
//創(chuàng)建一個(gè)位圖對(duì)象
Bitmap image = new Bitmap(w, w);
//創(chuàng)建Graphics
Graphics g = Graphics.FromImage(image);
try
{
//清空?qǐng)D片背景顏色
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();
}
}
}
}
相關(guān)文章
詳解C#如何利用爬蟲技術(shù)實(shí)現(xiàn)快捷租房
做為一個(gè)碼農(nóng),大部分都集中在一二線城市,所以租房也就無可避免,面對(duì)如今五花八門的租房信息,往往很難找到合適的房子。本文教你如何利用爬蟲技術(shù)實(shí)現(xiàn)快捷租房,感興趣的可以了解一下2022-09-09使用C#創(chuàng)建Windows服務(wù)的實(shí)例代碼
這篇文章主要介紹了使用C#創(chuàng)建Windows服務(wù)的實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-07-07C#微信公眾平臺(tái)開發(fā)之高級(jí)群發(fā)接口
這篇文章主要為大家詳細(xì)介紹了C#微信公眾平臺(tái)開發(fā)之高級(jí)群發(fā)接口的相關(guān)資料,需要的朋友可以參考下2016-03-03C#請(qǐng)求http向網(wǎng)頁發(fā)送接收數(shù)據(jù)的方法
這篇文章主要為大家詳細(xì)介紹了C#請(qǐng)求http向網(wǎng)頁發(fā)送數(shù)據(jù)、網(wǎng)頁接收的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07C# InitializeComponent()方法案例詳解
這篇文章主要介紹了C# InitializeComponent()方法案例詳解,本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-08-08