Use graphics to export images. [This is only code and will be improved in the future .]

Source: Internet
Author: User
/// <Summary> // export the signaling process vector graph /// </Summary> /// <Param name = "signalflowinfos"> signaling process </param> // /<returns> path </returns> Public String exporttoimage (list <signalflowinfo> List) {list <signalopinion> signalopinionlist = getsignalopinion (); seriesopinionoffsetdic = new dictionary <string, int> (); seriesopinionbrushdic = new dictionary <string, brush> (); string [] seriesnamearr = new string [signalopinionlist. cou NT]; for (INT I = 0; I <signalopinionlist. count; I ++) {seriesopinionoffsetdic. add (signalopinionlist [I]. name, 80 + itemwidth * I); seriesopinionbrushdic. add (signalopinionlist [I]. name, new solidbrush (color. fromargb (signalopinionlist [I]. colora, signalopinionlist [I]. colorr, signalopinionlist [I]. colorg, signalopinionlist [I]. colorb); seriesnamearr [I] = signalopinionlist [I]. name;} int imgwidth = 80 + signalop Inionlist. Count * itemwidth; bitmap BMP = new Bitmap (imgwidth, (list. Count + 2) * itemheight); graphics GS = graphics. fromimage (BMP); If (! Directory. exists (tempfilespath) {directory. createdirectory (tempfilespath);} string filename = "signaling flowchart" + system. guid. newguid (). tostring () + ". zip "; string filepath = tempfilespath +" \ "+ filename; Metafile mf = NULL; graphics G = NULL; try {mf = new Metafile (filepath, Gs. gethdc (); G = graphics. fromimage (MF); drawnew (G, list, seriesnamearr); G. save ();} catch (exception ERR) {webloglayout. err Or (new list <string> () {"failed to export the signaling flow vector diagram:" + err. message}); // return ""; Exception E = new exception ("failed to export the signaling flow vector diagram", err); throw e ;}finally {If (G! = NULL) g. Dispose (); If (MF! = NULL) MF. dispose ();} return filename ;} /// <summary> /// drawing // </Summary> /// <Param name = "G"> GDI + drawing </param> /// <param name = "signalflowinfos"> data object set </param> private void drawnew (Graphics G, list <signalflowinfo> signalflowinfos, string [] seriesnamearr) {int imgwidth = 80 + seriesnamearr. length * itemwidth; // canvas width int imgheight = (signalflowinfos. count + 2) * itemheight; // canvas height font fonttitle = New font ("", 12, fontstyle. bold); font = new font ("", 9, fontstyle. regular); # region defines the header point celllocation = new point (5, 5); stringformat format = new stringformat (); format. alignment = stringalignment. center; format. linealignment = stringalignment. center; rectangle cellrect; Pen = new pen (brushes. black, 1); For (INT I = 0; I <seriesnamearr. length; I ++) {string name = seriesname Arr [I]; cellrect = new rectangle (seriesopinionoffsetdic [name] + (itemWidth-100)/2, 5,100, 30); // 100 is the width of the rectangle tittle // G. fillrectangle (seriesopinionbrushdic [name], cellrect); createroundrectangle. fillroundrectangle (G, seriesopinionbrushdic [name], cellrect, 5); pen. brush = brushes. black; pen. dashstyle = system. drawing. drawing2d. dashstyle. solid; // draw the dotted line createroundrectangle. drawroundrectangle (G, pen, cellr ECT, 5); G. drawstring (name, fonttitle, brushes. black, seriesopinionoffsetdic [name] + itemwidth/2, 20, format); // pen = new pen (seriesopinionbrushdic [name], 2); // column color pen. brush = seriesopinionbrushdic [name]; pen. dashstyle = system. drawing. drawing2d. dashstyle. dot; // draw the dotted pen. dashpattern = new float [] {3, 2}; int xline = seriesopinionoffsetdic [name] + itemwidth/2; G. drawline (pen, xline, 35, xline, imgh Eight); // draw a column} # endregion int hight = 35; color colorto = colortranslator. fromhtml ("#008000"); // color to the right colorfrom = colortranslator. fromhtml ("# ffa500"); // color to the left: String fromx1name; string tox2name; int seriesoffsetto; int seriesoffsetfrom; pen. dashstyle = system. drawing. drawing2d. dashstyle. solid; // draw the solid line for (INT I = 0; I <signalflowinfos. count; I ++) {# region first line fromx1name = signalflowinfos [I]. From; tox2name = signalflowinfos [I]. to; seriesoffsetto = response [tox2name] + itemwidth/2; seriesoffsetfrom = response [fromx1name] + itemwidth/2; cellrect = new rectangle (6, hight + 1, imgwidth, itemheight ); format. alignment = stringalignment. near; G. drawstring (signalflowinfos [I]. time, Font, brushes. black, cellrect, format); // connection line and arrow pen. width = 2; If (array. indexo F (seriesnamearr, fromx1name) <array. indexof (seriesnamearr, tox2name) // draw the right arrow {pen. color = colorto; G. drawline (pen, seriesoffsetto-10, hight + itemheight/2-5, seriesoffsetto-5, hight + itemheight/2); // online G. drawline (pen, seriesoffsetto-10, hight + itemheight/2 + 5, seriesoffsetto-5, hight + itemheight/2 ); // offline} else // draw the left arrow {pen. color = colorfrom; G. drawline (pen, seriesoffsetto + 5, high T + itemheight/2, seriesoffsetto + 10, hight + itemheight/2-5); // online G. drawline (pen, seriesoffsetto + 5, hight + itemheight/2, seriesoffsetto + 10, hight + itemheight/2 + 5); // offline} pen. width = 1; G. drawline (pen, seriesoffsetfrom, hight + itemheight/2, seriesoffsetto, hight + itemheight/2); cellrect = new rectangle (seriesoffsetfrom-5, hight + itemheight/2-5, 10, 10); G. fillellipse (seriesopinio Nbrushdic [fromx1name], cellrect); // circle G. drawellipse (pens. black, cellrect); // draw the border cellrect = new rectangle (seriesoffsetto-5, hight + itemheight/2-5, 10, 10); G. fillellipse (seriesopinionbrushdic [tox2name], cellrect); G. drawellipse (pens. black, cellrect); // write message cellrect = new rectangle (seriesoffsetfrom <seriesoffsetto? Seriesoffsetfrom: seriesoffsetto, hight, itemwidth-10, itemheight); format. alignment = stringalignment. center; G. drawstring (signalflowinfos [I]. message, Font, brushes. black, cellrect, format); # endregion hight + = itemheight ;}}

 

Use graphics to export images. [This is only code and will be improved in the future .]

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.