怎样将c#生成的wmf文件中的字体转化曲线?

来源:百度知道 编辑:UC知道 时间:2024/06/06 08:02:24
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;

namespace test
{
class Program
{
static void Main(string[] args)
{
string filePath = "c:\\test.wmf";
Bitmap bmp = new Bitmap(10, 10);
Graphics gs = Graphics.FromImage(bmp);
Rectangle rect = new Rectangle(0, 0, 100, 100);
Metafile mf = new Metafile(filePath, gs.GetHdc(), rect, MetafileFrameUnit.Pixel);
Graphics g = Graphics.FromImage(mf);
g.DrawString("剖面图", new Font("宋体", 9f), Brushes.Green, 0f, 0f);
g.Save();
g.Dispose();
mf.Dispose();
}
}
}
文件生成在c:\test.wmf。将其插入ms-word程序,编辑它,发现“剖面图”三个字是在一个文本框中,可以编辑。那么现在的问题是,如果要把“剖面图”三个字变成由曲线形成的图形,该怎么办?
已解决。

/// <summary>
/// 正弦曲线Wave扭曲图片(Edit By crazycoder.cn)
/// </summary>
/// <param name="srcBmp">图片路径</param>
/// <param name="bXDir">如果扭曲则选择为True</param>
/// <param name="nMultValue">波形的幅度倍数,越大扭曲的程度越高,一般为3</param>
/// <param name="dPhase">波形的起始相位,取值区间[0-2*PI)</param>
/// <returns></returns>
public System.Drawing.Bitmap TwistImage(Bitmap srcBmp, bool bXDir, double dMultValue, double dPhase)
{
System.Drawing.Bitmap destBmp = new Bitmap(srcBmp.Width, srcBmp.Height);

// 将位图背景填充为白色
System.Drawing.Graphics graph = System.Drawing.Graphics.FromImage(destBmp);
graph.FillRectangle(new SolidBrush(System.Drawing.Color.White), 0, 0, destBmp.Width, destBmp.Height);
graph.Dispose();