Advertisement
Guest User

Untitled

a guest
Mar 18th, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1.     public class UtilityController : Controller
  2.     {
  3.         //
  4.         // GET: /Utility/
  5.         public ContentResult SvgBuilder(string stops)
  6.         {
  7.             string[] values = stops.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  8.  
  9.             var sb = new StringBuilder();
  10.             sb.Append("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"100%\" height=\"100%\">");
  11.             sb.AppendLine();
  12.             sb.Append("<defs>");
  13.             sb.AppendLine();
  14.             sb.Append("<linearGradient id=\"linear-gradient\" x1=\"0%\" y1=\"0%\" x2=\"0%\" y2=\"100%\">");
  15.             sb.AppendLine();
  16.  
  17.             foreach (var val in values)
  18.             {
  19.                 string[] items = val.Split(new Char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  20.                 sb.Append("<stop offset=\"" + items[1] + "\" stop-color=\"" + items[0] + "\" stop-opacity=\"1\"/>");
  21.                 sb.AppendLine();
  22.             }
  23.  
  24.             sb.Append("</linearGradient>");
  25.             sb.AppendLine();
  26.             sb.Append("</defs>");
  27.             sb.AppendLine();
  28.             sb.Append("<rect width=\"100%\" height=\"100%\" fill=\"url(#linear-gradient)\"/>");
  29.             sb.AppendLine();
  30.             sb.Append("</svg>");
  31.             sb.AppendLine();
  32.  
  33.             return Content(sb.ToString(), "image/svg+xml");
  34.         }
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement