Infinite source C # draw vector graphics [original]
Recently involved in a project, the main function of the software is to use C # to draw vector images, and then export to Word, Excel, PowerPoint, and can be edited again. Here's how we solve the process:
You should first determine the format in which you can edit graphics in your Office documents, and learn about the format of Office documents that support three vector diagrams :1,VML Graphics , 2, WMF file Format , 3,EMF file format . because the VML diagram is generally described in HTML language, it is not easy to operate, so it is decided to use the WMF and EMF file formats.
The next step is to have C # generate vector graphics in WMF or EMF format based on the data provided, and learn the GDI + drawing class library provided by C #, where GDI + can draw vector graphics with the following code examples:
<summary>///Export to EMF or WMF file///</summary>//<param name= "FilePath" > File path </param>// /<returns> is successful </returns> private bool Export (string filePath) {try {Bitmap bmp = new Bitmap (220,22 0); 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 graphics////</summary>//<param name= "G" > Graphics object for drawing </param> privat e 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), 10f,10f,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,6,208,208); G.drawline (New Pen (color.black,0.1f), 110f,110f,220f,25f); g.DrawString ("section view", New Font ("Arial", 9f), brushes.green,220f,20f);}
The resulting graphs are as follows:
Magnification effect:
To edit the effect of a graphic in Word:
At this point, the technical requirements of the software are realized.
[Go] C # draw vector graphics