我需要在所需位置绘制任意角度的旋转文本,图像应采用emf格式。因此,它可以是办公文档中的可编辑文本。我需要使用c#或GDI命令。
如果有可能,请提供示例代码段。
谢谢, LOKESH
答案 0 :(得分:0)
此代码演示如何使用旋转文本创建元文件,并在调试输出中显示元文件记录的实际内容。
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