The main function is to use C # To draw a vector graph, export it to Word, Excel, and Powerpoint, and edit it again. The solution is as follows:
First, you should determine the format that can be used to edit images in the Office document. after learning the relevant materials, we learned that Office documents mainly support three vector graph formats: 1. VML graphics, 2. WMF file format. 3. EMF file format. Because VML diagrams are generally described in HTML language and are not easy to operate, the WMF and EMF file formats are used.
The next step is to let C # generate a WMF or EMF vector Image Based on the provided data; learn the GDI + drawing class library provided by C #, And the GDI + can draw a vector image, the sample code is as follows:
/// <Summary>
/// Export as an Emf or Wmf File
/// </Summary>
/// <Param name = "filePath"> file path </param>
/// <Returns> Successful </returns>
Private bool Export (string filePath)
{
Try
{
Bitmap bmp = new Bitmap (220,220 );
Graphics gs = Graphics. FromImage (bmp );
Metafile mf = new Metafile (filePath, gs. GetHdc ());
Graphics g = Graphics. FromImage (mf );
Draw (g );
G. Save ();
G. Dispose ();
Mf. Dispose ();
Return true;
}
Catch
{
Return false;
}
}
/// <Summary>
/// Draw the image
/// </Summary>
/// <Param name = "g"> Graphics object used for drawing </param>
Private void Draw (Graphics g)
{
HatchBrush hb = new HatchBrush (HatchStyle. LightUpwardDiagonal, Color. Black, Color. White );
G. FillEllipse (Brushes. Gray, 10f, 10f, 200,200 );
G. DrawEllipse (new Pen (Color. Black, 1f), 10 F, 10 F, 200,200 );
G. FillEllipse (hb, 30f, 95f, 30,30 );
G. DrawEllipse (new Pen (Color. Black, 1f), 30f, 95f, 30,30 );
G. FillEllipse (hb, 160f, 95f, 30,30 );
G. DrawEllipse (new Pen (Color. Black, 1f), 160f, 95f, 30,30 );
G. FillEllipse (hb, 95f, 30f, 30,30 );
G. DrawEllipse (new Pen (Color. Black, 1f), 95f, 30f, 30,30 );
G. FillEllipse (hb, 95f, 160f, 30,30 );
G. DrawEllipse (new Pen (Color. Black, 1f), 95f, 160f, 30,30 );
G. FillEllipse (Brushes. Blue, 60f, 60f, 100,100 );
G. DrawEllipse (new Pen (Color. Black, 1f), 60f, 60f, 100,100 );
G. FillEllipse (Brushes. BlanchedAlmond, 95f, 95f, 30,30 );
G. DrawEllipse (new Pen (Color. Black, 1f), 95f, 95f, 30,30 );
G. DrawRectangle (new Pen (System. Drawing. Brushes. Blue, 0.1f), 6, 208,208 );
G. DrawLine (new Pen (Color. Black, 0.1f), 110f, 110f, 220f, 25f );
G. DrawString ("Profile", new Font ("", 9f), Brushes. Green, 220f, 20f );
}
The generated image is as follows:
After amplification: