0

I am in need to draw a rotated text of any angle in a desired location and the image should be in emf format .so that it can be a editable text in the office documents.I need this to be done using c# or GDI commands.

Please,if it possible post me with a sample code snippet.

Thanks, Lokesh

Lokesh
  • 829
  • 2
  • 14
  • 26

1 Answers1

0

This code demonstrates creating a metafile with rotated text and shows in the debug output what the metafile records actually look like.

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;
}

The output in the debug window is:

EmfMin 0
Header 0
RotateWorldTransform 0
Object 1536
DrawString 32768
EndOfFile 0
EmfEof 0
BlueMonkMN
  • 25,079
  • 9
  • 80
  • 146