<% @ Webhandler Language = "C #" class = "drawline1" %> Using system; Using system. Web; Using system. Collections. Generic; Using system. drawing; Using system. Drawing. drawing2d; Using system. IO; Using system. Drawing. imaging; Public class drawline1: ihttphandler { Public void processrequest (httpcontext context) { List <point> points = getpointarray1 (); Using (Bitmap chartingimage = new Bitmap (320,240 )) { Using (Graphics G = graphics. fromimage (chartingimage )) { // Specify the use of smooth processing (also known as the Anti-sawtooth function ). G. smoothingmode = smoothingmode. antialias; G. fillrectangle (New lineargradientbrush (New rectangle (0, 0,320,240), color. deeppink, color. yellowgreen, lineargradientmode. Vertical), new rectangle (0, 0,320,240 )); Using (pen p = new pen (color. Yellow, 2 )) { If (points. Count> 1) { Int startx = points [0]. X; Int starty = points [0]. Y; For (INT I = 1; I <points. Count; I ++) { G. drawline (p, startx, starty, points [I]. X, points [I]. y ); Startx = points [I]. X; Starty = points [I]. Y; } G. drawstring ("Shenzhen A shares:" + convert. tostring (240-points [points. count-1]. y), new font ("", 20), brushes. yellow, 0, 0 ); } } Using (pen p = new pen (color. Red, 2 )) { If (points. Count> 1) { Int startx = points [0]. x + 20; Int starty = points [0]. Y-10; For (INT I = 1; I <points. Count; I ++) { G. drawline (p, startx, starty, points [I]. x + 20, points [I]. Y-10 ); Startx = points [I]. x + 20; Starty = points [I]. Y-10; }
} } Context. response. contenttype = "image/PNG "; Context. response. cache. setnostore (); Context. response. cache. setcacheability (httpcacheability. nocache ); Context. response. cache. setexpires (datetime. Now ); Context. response. cache. setvaliduntilexpires (false ); Using (memorystream MS = new memorystream ()) { Chartingimage. Save (MS, imageformat. PNG ); Ms. Flush (); Context. response. binarywrite (Ms. getbuffer ()); } } } } Private list <point> getpointarray1 () { List <point> points = (list <point>) (httpcontext. Current. cache ["pointarray1"]); If (points = NULL) { Points = new list <point> (); Points. Add (new point (0,120); // Add the first coordinate point (0,120 ). Httpcontext. Current. cache ["X1"] = 0; Httpcontext. Current. cache ["Y1"] = 120; } Random r = new random (); Int x = convert. toint32 (httpcontext. Current. cache ["X1"]) + 10; Int y = convert. toint32 (httpcontext. Current. cache ["Y1"]); If (x = 320) { X = 0; Y = 120; Points. Clear (); } If (Y % 2 = 0) { Y + = R. Next (0, 11 ); } Else { Y-= R. Next (0, 11 ); } Points. Add (new point (x, y )); Httpcontext. Current. cache ["pointarray1"] = points; Httpcontext. Current. cache ["X1"] = X; Httpcontext. Current. cache ["Y1"] = y; Return points; }
Public bool isreusable { Get { Return false; } } } |