0
我需要在所需的位置繪製任意角度的旋轉文本,並且圖像應採用emf格式,因此它可以是辦公文檔中的可編輯文本我需要使用c#或GDI命令來完成此操作。如何在Meta文件中繪製旋轉的文本
請,如果有可能發佈我的示例代碼片段。
感謝, LOKESH
我需要在所需的位置繪製任意角度的旋轉文本,並且圖像應採用emf格式,因此它可以是辦公文檔中的可編輯文本我需要使用c#或GDI命令來完成此操作。如何在Meta文件中繪製旋轉的文本
請,如果有可能發佈我的示例代碼片段。
感謝, 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