110,538
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
ImageMain("1", "15", "", "", "MingLiu", "要生成的字", "c:\\11.jpg"); ;
}
/// <summary>
/// 基本样式处理
/// </summary>
/// <param name="fontnum">艺术字编号</param>
/// <param name="fontsize">字体大小</param>
/// <param name="fontimagesizewith">图片宽</param>
/// <param name="fontimagesizehigh">图片高</param>
/// <param name="fonttype">字体书写类别</param>
/// <param name="fonttxt">字体文本</param>
/// <param name="path">艺术字保存路径</param>
/// <returns>成功返回true失败返回false</returns>
public static bool ImageMain(string fontnum, string fontsize, string fontimagesizewith, string fontimagesizehigh, string fonttype, string fonttxt, string path)
{
bool is_ok = true;
try
{
string wz = fonttxt;
string filePath = path;
Bitmap bmp = new Bitmap(10, 10);
Graphics gs = Graphics.FromImage(bmp);
if (fontimagesizewith == "" || fontimagesizehigh == "")
{
if (fontnum == "6")
{
fontimagesizewith = (Convert.ToInt32(fontsize) * 2 * wz.Length).ToString();
fontimagesizehigh = (Convert.ToInt32(fontsize) * wz.Length).ToString();
}
else
{
fontimagesizewith = (Convert.ToInt32(fontsize) * 2 * wz.Length).ToString();
fontimagesizehigh = (Convert.ToInt32(fontsize) * 4).ToString();
}
}
Rectangle rect = new Rectangle(0, 0, Convert.ToInt32(fontimagesizewith), Convert.ToInt32(fontimagesizehigh));
Metafile mf = new Metafile(filePath, gs.GetHdc(), rect, MetafileFrameUnit.Pixel);
Graphics g = Graphics.FromImage(mf);
//文本样式
Font newFont = new Font(fonttype, Convert.ToInt16(fontsize), FontStyle.Italic);
if (fontnum == "1")
{
Matrix matrix = new Matrix();
//投射
matrix.Shear(-1.5f, 0.0f);
//缩放
matrix.Scale(1, 0.5f);
//平移
matrix.Translate(130, 88);
//对绘图平面实施坐标变换、、
g.Transform = matrix;
//阴影样式
SolidBrush grayBrush = new SolidBrush(Color.Gray);
//正文颜色
SolidBrush colorBrush = new SolidBrush(Color.BlueViolet);
//绘制阴影
g.DrawString(wz, newFont, grayBrush, new PointF(0, 30));
g.ResetTransform();
//绘制前景
g.DrawString(wz, newFont, colorBrush, new PointF(0, 30));
}
g.Save();
g.Dispose();
mf.Dispose();
return is_ok;
}
catch (Exception e)
{
return false;
}
}
}
}