Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Mar 18th, 2012  |  syntax: C#  |  size: 1.37 KB  |  views: 52  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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.     }
clone this paste RAW Paste Data