The SVG format is used to convert the files in,

Source: Internet
Author: User

The SVG format is used to convert the files in,

The SVG format can be directly displayed on a webpage to implement functions such as statistical Chart, flow Chart, and organization Chart. To enable downloading images for modification, you can convert SVG to. The method is very simple. The main method is to use the built-in methods of the Visio component. First open the svg file, and then save it as. The call method is as follows:

/// <Summary> /// convert svg to the left-side navigation pane of the left-side Navigation Pane. /// </summary> /// <param name = "svgFn"> svn file name </param> /// <param name = "desVsdFn"> name of the saved sealing file </param> private static void svg2sealing (string svgFn, string desVsdFn) {var app = ComObj. create ("Visio. application "); app [" Visible "] = new ComObj (false); var docs = app [" events "]; short visOpenHidden = 64, visOpenRO = 2; var doc = docs. call ("OpenEx", svgFn, visOpenHidden + visOpenRO); doc. call ("SaveAs", desVsdFn); doc. call ("Close"); var win = app ["Window"]; app. call ("Quit ");}

Here we use a self-written ComObj class, which is used to call Com components such as Office through reflection, and the Code for calling is concise and clear!

Why do we need to use reflection instead of directly referencing Com components for dynamic calling? The main purpose is to reduce the dependency coupling between program code and Com components, so as to facilitate code compilation, release, and deployment. Dynamic call method, you can compile and run without adding a reference to the component. If the Com component is not installed on the server, you can also make an intuitive prompt, instead of program errors.

The code for this class is as follows:

Using System; using System. reflection; namespace HZ. common {/// <summary> /// used to conveniently call attributes and methods of Com objects. /// </summary> public class ComObj {public static ComObj Create (string progId) {var type = Type. getTypeFromProgID (progId); if (type = null) {throw new Exception ("the server needs to install" + progId + "to use this function");} return new ComObj (Activator. createInstance (type);} private object _ val; // <summary> // actual value /// </sum Mary> public object Val {get {return _ val;} public ComObj (object comObject) {_ val = comObject;} public ComObj Call (string mehtodd, params object [] args) {if (_ val = null) return null; var ret = _ val. getType (). invokeMember (mehtodd, BindingFlags. invokeMethod, null, _ val, args); return new ComObj (ret);} public ComObj this [string property] {get {if (_ val = null) return null; var ret = _ val. GetType (). InvokeMember (property, BindingFlags. GetProperty, null, _ val, null); return new ComObj (ret);} set {if (_ val! = Null) _ val. GetType (). InvokeMember (property, BindingFlags. SetProperty, null, _ val, new object [] {value. Val });}}}}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.