C# 如何在元文件中绘制旋转文本
我需要在所需的位置绘制任意角度的旋转文本,并且图像应为emf格式。这样它就可以成为office文档中的可编辑文本。我需要使用c或GDI命令完成此操作 如果可能的话,请给我发一个示例代码片段 谢谢,C# 如何在元文件中绘制旋转文本,c#,C#,我需要在所需的位置绘制任意角度的旋转文本,并且图像应为emf格式。这样它就可以成为office文档中的可编辑文本。我需要使用c或GDI命令完成此操作 如果可能的话,请给我发一个示例代码片段 谢谢, Lokesh这段代码演示了如何使用旋转文本创建图元文件,并在调试输出中显示图元文件记录的实际外观 System.Drawing.Imaging.Metafile metaFile; public Form1() { InitializeComponent(); using(Graphi
Lokesh这段代码演示了如何使用旋转文本创建图元文件,并在调试输出中显示图元文件记录的实际外观
System.Drawing.Imaging.Metafile metaFile;
public Form1()
{
InitializeComponent();
using(Graphics g = Graphics.FromHwnd(this.Handle))
{
IntPtr hdc = g.GetHdc();
try
{
metaFile = new System.Drawing.Imaging.Metafile(hdc, System.Drawing.Imaging.EmfType.EmfPlusOnly);
}
finally
{
g.ReleaseHdc(hdc);
}
}
using (Graphics g = Graphics.FromImage(metaFile))
{
g.RotateTransform(45);
g.DrawString("Test", this.Font, SystemBrushes.WindowText, 0, 0);
}
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawImage(metaFile, 20, 20);
e.Graphics.DrawImage(metaFile, 30, 30);
e.Graphics.EnumerateMetafile(metaFile, Point.Empty, MetafileCallback);
}
private bool MetafileCallback(System.Drawing.Imaging.EmfPlusRecordType type, int flags, int dataSize, IntPtr data, System.Drawing.Imaging.PlayRecordCallback callbackData)
{
System.Diagnostics.Debug.WriteLine(string.Format("{0} {1}", type, flags));
return true;
}
调试窗口中的输出为:
EmfMin 0
Header 0
RotateWorldTransform 0
Object 1536
DrawString 32768
EndOfFile 0
EmfEof 0