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: