SvgHelper.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. using DevExpress.Utils;
  2. using DevExpress.Utils.Svg;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data.SqlTypes;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.IO.Ports;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Xml;
  13. namespace DxHelper
  14. {
  15. public static class SvgHelper
  16. {
  17. static readonly Dictionary<string, SvgImage> cache = new Dictionary<string, SvgImage>();
  18. /// <summary>
  19. /// 判断color是否为HtmlColor(HtmlColor格式如#A1B2C3)
  20. /// </summary>
  21. /// <param name="color"></param>
  22. /// <returns></returns>
  23. public static bool IsHtmlColor(string color)
  24. {
  25. if (!color.StartsWith("#")) return false;
  26. if (color.Length != 7) return false;
  27. string r = color.Substring(1, 2);
  28. string g = color.Substring(3, 2);
  29. string b = color.Substring(5, 2);
  30. bool r1 = byte.TryParse(r, System.Globalization.NumberStyles.HexNumber, null, out _);
  31. bool r2 = byte.TryParse(g, System.Globalization.NumberStyles.HexNumber, null, out _);
  32. bool r3 = byte.TryParse(b, System.Globalization.NumberStyles.HexNumber, null, out _);
  33. return r1 & r2 & r3;
  34. }
  35. /// <summary>
  36. /// 将SvgImage转换为Image对象
  37. /// </summary>
  38. /// <param name="svg"></param>
  39. /// <param name="width"></param>
  40. /// <param name="height"></param>
  41. /// <returns></returns>
  42. public static Image SvgToImage(SvgImage svg, int width, int height)
  43. {
  44. var img = svg.Render(new Size(width, height), null, DefaultBoolean.False, DefaultBoolean.False);
  45. return img;
  46. }
  47. /// <summary>
  48. /// 将文件转换为SvgImage对象
  49. /// </summary>
  50. /// <param name="svgFile"></param>
  51. /// <returns></returns>
  52. public static SvgImage LoadFromFile(string svgFile)
  53. {
  54. return SvgLoader.LoadFromFile(svgFile);
  55. }
  56. /// <summary>
  57. /// 新增图片(➕号)
  58. /// </summary>
  59. /// <param name="color"></param>
  60. /// <param name="width"></param>
  61. /// <param name="height"></param>
  62. /// <returns></returns>
  63. public static SvgImage CreateAdd(string color = "#039C23", int width = 24, int height = 24)
  64. {
  65. string xml = $"<svg xmlns='http://www.w3.org/2000/svg\' width='{width}px' height='{height}px' viewBox='0 0 32 32'>"
  66. + $"<path fill='{color}' d='M27,14h-9V5c0-0.5-0.5-1-1-1h-2c-0.5,0-1,0.5-1,1v9H5c-0.5,0-1,0.5-1,1v2c0,0.5,0.5,1,1,1h9v9c0,0.5,0.5,1,1,1h2c0.5,0,1-0.5,1-1v-9h9c0.5,0,1-0.5,1-1v-2C28,14.5,27.5,14,27,14z'/>"
  67. + "</svg>";
  68. MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xml));
  69. var svg = SvgLoader.LoadFromStream(ms);
  70. ms.Dispose();
  71. return svg;
  72. }
  73. /// <summary>
  74. /// 编辑图片
  75. /// </summary>
  76. /// <param name="color"></param>
  77. /// <param name="width"></param>
  78. /// <param name="height"></param>
  79. /// <returns></returns>
  80. public static SvgImage CreateEdit(string color = "#1177D7", int width = 24, int height = 24)
  81. {
  82. string xml = $"<svg xmlns='http://www.w3.org/2000/svg\' width='{width}px' height='{height}px' viewBox='0 0 32 32'>"
  83. + $"<path fill='{color}' d='M27.6,8.2l-3.8-3.8c-0.5-0.5-1.4-0.5-1.9,0l-2.5,2.5l5.8,5.8l2.5-2.5C28.1,9.6,28.1,8.8,27.6,8.2z'/>"
  84. + $"<polygon fill='{color}' points='4,28 9.8,28 4,22.2'/>"
  85. + $"<rect fill='{color}' x='5.8' y='13.4' transform='matrix(0.707 -0.7072 0.7072 0.707 -8.0721 15.4048)' width='17.6' height='8.2'/>"
  86. + "</svg>";
  87. MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xml));
  88. var svg = SvgLoader.LoadFromStream(ms);
  89. ms.Dispose();
  90. return svg;
  91. }
  92. /// <summary>
  93. /// 移除图片(➖号)
  94. /// </summary>
  95. /// <param name="color"></param>
  96. /// <param name="width"></param>
  97. /// <param name="height"></param>
  98. /// <returns></returns>
  99. public static SvgImage CreateRemove(string color = "#1177D7", int width = 24, int height = 24)
  100. {
  101. string xml = $"<svg xmlns='http://www.w3.org/2000/svg\' width='{width}px' height='{height}px' viewBox='0 0 32 32'>"
  102. + $"<path fill='{color}' d='M27,18H5c-0.6,0-1-0.5-1-1v-2c0-0.6,0.4-1,1-1h22c0.5,0,1,0.4,1,1v2C28,17.5,27.5,18,27,18z'/>"
  103. + "</svg>";
  104. MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xml));
  105. var svg = SvgLoader.LoadFromStream(ms);
  106. ms.Dispose();
  107. return svg;
  108. }
  109. /// <summary>
  110. /// 创建一个Svg圆.该圆的圆心在ViewBox的中心
  111. /// </summary>
  112. /// <param name="colorKey">用于生成颜色的一个key,相同的key具有相同的颜色,当colorKey为html颜色时则使用此颜色(如#A1B2FF)</param>
  113. /// <param name="opacity">透明度,默认不透明</param>
  114. /// <param name="viewBoxWidth">视口宽度,默认32px</param>
  115. /// <param name="viewBoxHeight">视口高度,默认32px</param>
  116. /// <param name="radius">半径,默认16px</param>
  117. /// <param name="offsetX">圆心的X轴偏移量,负向左偏移,正向右偏移,默认为0处于视口中心</param>
  118. /// <returns></returns>
  119. public static SvgImage CreateCycle(string colorKey, double opacity = 1, int viewBoxWidth = 32, int viewBoxHeight = 32, int radius = 16, double offsetX = 0)
  120. {
  121. if (colorKey == null) colorKey = "";
  122. if (cache.ContainsKey(colorKey))
  123. return cache[colorKey];
  124. SvgImage svg = new SvgImage();
  125. SvgRoot root = SvgRoot.Create(new SvgElementProperties(), viewBox: new SvgViewBox(0, 0, viewBoxWidth, viewBoxHeight));
  126. svg.Elements.Add(root);
  127. string colorStr;
  128. if (IsHtmlColor(colorKey))
  129. colorStr = colorKey;
  130. else
  131. colorStr = ColorHelper.GetHtmlColor(colorKey);
  132. SvgElementProperties props = new SvgElementProperties
  133. {
  134. Fill = colorStr,
  135. Opacity = opacity//透明度
  136. };
  137. SvgCircle circle = SvgCircle.Create(props, viewBoxWidth / 2 + offsetX, viewBoxHeight / 2, radius);
  138. root.Elements.Add(circle);
  139. //SvgImage未公开Width和Height属性的公共写入,需要通过以下方式可对width和Size赋值
  140. MemoryStream ms = new MemoryStream();
  141. svg.Save(ms);
  142. svg = ms.ToArray();
  143. cache.Add(colorKey, svg);
  144. ms.Dispose();
  145. return svg;
  146. }
  147. /// <summary>
  148. /// 删除或关闭图片(一个叉叉)
  149. /// </summary>
  150. /// <param name="colorStr"></param>
  151. /// <param name="opacity"></param>
  152. /// <returns></returns>
  153. public static SvgImage CreateClose(string colorStr = "#D11C1C", double opacity = 1)
  154. {
  155. if (string.IsNullOrWhiteSpace(colorStr))
  156. colorStr = $"#D11C1C";
  157. string xml = $"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox='0 0 32 32'>\r\n<g>\r\n<path opacity=\"{opacity}\" fill=\"{colorStr}\" d=\"M18.8,16l6.9-6.9c0.4-0.4,0.4-1,0-1.4l-1.4-1.4c-0.4-0.4-1-0.4-1.4,0L16,13.2L9.1,6.3c-0.4-0.4-1-0.4-1.4,0\r\nL6.3,7.7c-0.4,0.4-0.4,1,0,1.4l6.9,6.9l-6.9,6.9c-0.4,0.4-0.4,1,0,1.4l1.4,1.4c0.4,0.4,1,0.4,1.4,0l6.9-6.9l6.9,6.9\r\nc0.4,0.4,1,0.4,1.4,0l1.4-1.4c0.4-0.4,0.4-1,0-1.4L18.8,16z\"/>\r\n</g>\r\n</svg>";
  158. MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xml));
  159. var svg = SvgLoader.LoadFromStream(ms);
  160. ms.Dispose();
  161. return svg;
  162. }
  163. /// <summary>
  164. /// 清除图片(一个橡皮擦)
  165. /// </summary>
  166. /// <returns></returns>
  167. public static SvgImage CreateClear()
  168. {
  169. string xml = $"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox='0 0 32 32'>\r\n<path class=\"Blue\" d=\"M16.1,23.1l-4.4,4.4c-0.7,0.7-1.9,0.7-2.6,0l-6.6-6.6c-0.7-0.7-0.7-1.9,0-2.6L6.9,14L16.1,23.1z\"/><path class=\"Red\" d=\"M27.5,11.8l-10,10l-9.2-9.2l10-10c0.7-0.7,1.9-0.7,2.6,0l6.6,6.6C28.2,9.9,28.2,11,27.5,11.8z\"/></svg>";
  170. MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xml));
  171. var svg = SvgLoader.LoadFromStream(ms);
  172. ms.Dispose();
  173. return svg;
  174. }
  175. /// <summary>
  176. /// 测距图片
  177. /// </summary>
  178. /// <returns></returns>
  179. public static SvgImage CreateDistanceLine()
  180. {
  181. string xml = $"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox='0 0 32 32'>"
  182. + "<path class=\"Blue\" d=\"M27,8c-1.7,0-3,1.3-3,3c0,0.5,0.1,0.9,0.3,1.3l-6,6C17.9,18.1,17.5,18,17,18s-0.9,0.1-1.3,0.3l-2-2\r\n\t\tc0.2-0.4,0.3-0.8,0.3-1.3c0-1.7-1.3-3-3-3s-3,1.3-3,3c0,0.5,0.1,0.9,0.3,1.3l-2,2C5.9,18.1,5.5,18,5,18c-1.7,0-3,1.3-3,3s1.3,3,3,3\r\n\t\ts3-1.3,3-3c0-0.5-0.1-0.9-0.3-1.3l2-2c0.4,0.2,0.8,0.3,1.3,0.3s0.9-0.1,1.3-0.3l2,2C14.1,20.1,14,20.5,14,21c0,1.7,1.3,3,3,3\r\n\t\ts3-1.3,3-3c0-0.5-0.1-0.9-0.3-1.3l6-6c0.4,0.2,0.8,0.3,1.3,0.3c1.7,0,3-1.3,3-3S28.7,8,27,8z M5,22c-0.6,0-1-0.4-1-1s0.4-1,1-1\r\n\t\ts1,0.4,1,1S5.6,22,5,22z M11,16c-0.6,0-1-0.4-1-1s0.4-1,1-1s1,0.4,1,1S11.6,16,11,16z M17,22c-0.6,0-1-0.4-1-1s0.4-1,1-1s1,0.4,1,1\r\n\t\tS17.6,22,17,22z M27,12c-0.6,0-1-0.4-1-1s0.4-1,1-1s1,0.4,1,1S27.6,12,27,12z\"/>"
  183. + "</svg>";
  184. MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xml));
  185. var svg = SvgLoader.LoadFromStream(ms);
  186. ms.Dispose();
  187. return svg;
  188. }
  189. /// <summary>
  190. /// 标点图片(一个五角星)
  191. /// </summary>
  192. /// <param name="color"></param>
  193. /// <param name="width"></param>
  194. /// <param name="height"></param>
  195. /// <returns></returns>
  196. public static SvgImage CreateMarkDot(string color = "#F12233", int width = 24, int height = 24)
  197. {
  198. string xml = $"<svg xmlns=\"http://www.w3.org/2000/svg\" width='{width}px' height='{height}px' viewBox='0 0 32 32'>"
  199. + $"<path fill='{color}' d=\"M6,8c0,1.1-0.9,2-2,2c-1.1,0-2-0.9-2-2s0.9-2,2-2C5.1,6,6,6.9,6,8z M10,22c-1.1,0-2,0.9-2,2s0.9,2,2,2c1.1,0,2-0.9,2-2S11.1,22,10,22z M18,16c-1.1,0-2,0.9-2,2s0.9,2,2,2c1.1,0,2-0.9,2-2S19.1,16,18,16z M22,8c-1.1,0-2,0.9-2,2c0,1.1,0.9,2,2,2c1.1,0,2-0.9,2-2C24,8.9,23.1,8,22,8z M28,4c-1.1,0-2,0.9-2,2s0.9,2,2,2c1.1,0,2-0.9,2-2S29.1,4,28,4z\"/><path class=\"Yellow\" d=\"M8,18c0,1.1-0.9,2-2,2c-1.1,0-2-0.9-2-2s0.9-2,2-2C7.1,16,8,16.9,8,18z M12,10c-1.1,0-2,0.9-2,2s0.9,2,2,2c1.1,0,2-0.9,2-2S13.1,10,12,10z M4,26c-1.1,0-2,0.9-2,2s0.9,2,2,2c1.1,0,2-0.9,2-2S5.1,26,4,26z M20,2c-1.1,0-2,0.9-2,2s0.9,2,2,2\r\n\tc1.1,0,2-0.9,2-2S21.1,2,20,2z M28,12c-1.1,0-2,0.9-2,2s0.9,2,2,2c1.1,0,2-0.9,2-2S29.1,12,28,12z\"/>"
  200. + "</svg>";
  201. MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xml));
  202. var svg = SvgLoader.LoadFromStream(ms);
  203. ms.Dispose();
  204. return svg;
  205. }
  206. /// <summary>
  207. /// 接收天线
  208. /// </summary>
  209. /// <param name="color"></param>
  210. /// <param name="width"></param>
  211. /// <param name="height"></param>
  212. /// <returns></returns>
  213. public static SvgImage CreateAnt(string color = "#1177D7", int width = 24, int height = 24)
  214. {
  215. string xml = $"<svg xmlns=\"http://www.w3.org/2000/svg\" width='{width}px' height='{height}px' viewBox='0 0 329.871 329.871'>" + $"<path fill='{color}' d='M104.839,60c-8.284,0-15,6.716-15,15c0,8.284,6.716,15,15,15c74.439,0,135,60.561,135,135c0,8.284,6.716,15,15,15c8.284,0,15-6.716,15-15C269.839,134.018,195.82,60,104.839,60z'/> <path fill='{color}' d='M159.141,191.91l18.878-18.877c5.858-5.857,5.858-15.355,0.001-21.213c-5.858-5.858-15.355-5.858-21.214,0l-18.878,18.877l-76.34-76.34c-5.857-5.857-15.355-5.857-21.213,0c-53.791,53.791-53.791,141.314,0,195.105c26.057,26.059,60.701,40.408,97.553,40.408c36.852,0,71.496-14.35,97.553-40.408c5.857-5.857,5.857-15.355,0-21.213L159.141,191.91z'/>"
  216. + "</svg>";
  217. MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xml));
  218. var svg = SvgLoader.LoadFromStream(ms);
  219. ms.Dispose();
  220. return svg;
  221. }
  222. /// <summary>
  223. /// 圆点
  224. /// </summary>
  225. /// <param name="color"></param>
  226. /// <param name="width"></param>
  227. /// <param name="height"></param>
  228. /// <returns></returns>
  229. public static SvgImage CreateGeoDot(string color = "#D11C1C", int width = 24, int height = 24)
  230. {
  231. string xml = $"<svg xmlns=\"http://www.w3.org/2000/svg\" width='{width}px' height='{height}px' viewBox='0 0 32 32'>" + $"<path fill='{color}' d='M16,2C10.5,2,6,6.5,6,12s10,18,10,18s10-12.5,10-18S21.5,2,16,2z M16,16c-2.2,0-4-1.8-4-4s1.8-4,4-4s4,1.8,4,4S18.2,16,16,16z'/>"
  232. + "</svg>";
  233. MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xml));
  234. var svg = SvgLoader.LoadFromStream(ms);
  235. ms.Dispose();
  236. return svg;
  237. }
  238. /// <summary>
  239. /// 五角星图片
  240. /// </summary>
  241. /// <param name="color"></param>
  242. /// <param name="width"></param>
  243. /// <param name="height"></param>
  244. /// <returns></returns>
  245. public static SvgImage CreatePentagram(string color = "#1177D7", int width = 24, int height = 24)
  246. {
  247. string xml = $"<svg xmlns='http://www.w3.org/2000/svg\' width='{width}px' height='{height}px' viewBox='0 0 32 32'>" + $"<polygon fill='{color}' points='16,4 19.9,11.9 28.6,13.2 22.3,19.3 23.8,28 16,23.9 8.2,28 9.7,19.3 3.4,13.2 12.1,11.9'/>"
  248. + "</svg>";
  249. MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xml));
  250. var svg = SvgLoader.LoadFromStream(ms);
  251. ms.Dispose();
  252. return svg;
  253. }
  254. /// <summary>
  255. /// 卫星图片
  256. /// </summary>
  257. /// <param name="color"></param>
  258. /// <param name="width"></param>
  259. /// <param name="height"></param>
  260. /// <returns></returns>
  261. public static SvgImage CreateSat(string color = "#1177D7", int width = 24, int height = 24)
  262. {
  263. string xml = $"<svg xmlns=\"http://www.w3.org/2000/svg\" width='{width}px' height='{height}px' viewBox='0 0 297.131 297.131'>"
  264. + $"<path fill='{color}' d='M196.826,68.171c17.691,0.002,32.084,14.405,32.084,32.108c0,5.54,4.492,10.033,10.033,10.033 c5.54,0,10.033-4.493,10.033-10.033c0-28.768-23.394-52.173-52.148-52.175h-0.001c-5.54,0-10.033,4.491-10.033,10.032 C186.794,63.679,191.286,68.171,196.826,68.171z'/>"
  265. + $"<path fill='{color}' d='M196.827,34.094c36.476,0.002,66.15,29.692,66.15,66.186c0,5.54,4.492,10.033,10.033,10.033 c5.541,0,10.033-4.493,10.033-10.033c0-47.558-38.677-86.25-86.217-86.252c-5.54,0-10.033,4.491-10.033,10.033 C186.794,29.601,191.286,34.094,196.827,34.094z'/>"
  266. + $"<path fill='{color}' d='M187.387,160.099c13.264-13.271,13.264-34.984,0-48.254l-2.119-2.12c-6.631-6.635-15.374-9.952-24.115-9.952 c-8.743,0-17.484,3.316-24.116,9.953l-27.294,27.307c-13.264,13.271-13.264,34.984,0,48.254l2.12,2.12 c6.631,6.635,15.374,9.952,24.114,9.952c8.744,0,17.485-3.316,24.117-9.953L187.387,160.099z'/> "
  267. + $"<path fill='{color}' d='M98.388,125.684l27.295-27.307c7.865-7.869,17.917-12.782,28.811-14.212l-8.862-26.783 c-0.492-1.485-1.323-2.834-2.43-3.94L92.722,2.94C90.841,1.058,88.287,0,85.626,0c-2.662,0-5.215,1.059-7.097,2.94L3.001,78.505 c-3.915,3.918-3.915,10.269,0.002,14.186l50.48,50.501c1.106,1.107,2.456,1.938,3.941,2.432l26.752,8.861 C85.579,143.943,90.31,133.767,98.388,125.684z'/>"
  268. + $"<path fill='{color}' d='M294.128,204.439l-50.481-50.499c-1.107-1.106-2.456-1.938-3.941-2.43l-26.753-8.864 c-1.403,10.541-6.134,20.718-14.212,28.8l-27.294,27.308c-7.865,7.869-17.916,12.782-28.809,14.212l8.862,26.781 c0.492,1.484,1.323,2.834,2.429,3.941l50.478,50.503c1.882,1.882,4.435,2.94,7.097,2.94s5.215-1.058,7.096-2.94l75.529-75.564 C298.045,214.708,298.045,208.357,294.128,204.439z'/>"
  269. + "</svg>";
  270. MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xml));
  271. var svg = SvgLoader.LoadFromStream(ms);
  272. ms.Dispose();
  273. return svg;
  274. }
  275. public static SvgImage CreateRect(string color = "#1177D7", int width = 24, int height = 24)
  276. {
  277. string xml = $"<svg xmlns='http://www.w3.org/2000/svg\' width='{width}px' height='{height}px' viewBox='0 0 512 512'>"
  278. + $"<path fill='{color}' d='M0,0v512h512V0H0z M465.5,465.5H46.5V46.5h418.9V465.5z'/>"
  279. + "</svg>";
  280. MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xml));
  281. var svg = SvgLoader.LoadFromStream(ms);
  282. ms.Dispose();
  283. return svg;
  284. }
  285. /// <summary>
  286. /// 时隙参估图片
  287. /// </summary>
  288. /// <param name="color"></param>
  289. /// <param name="width"></param>
  290. /// <param name="height"></param>
  291. /// <returns></returns>
  292. public static SvgImage CreateSlotCg(string color = "#1177D7", int width = 24, int height = 24)
  293. {
  294. string xml = $"<svg xmlns='http://www.w3.org/2000/svg\' width='{width}px' height='{height}px' viewBox='0 0 32 32'>"
  295. + $"<path fill='{color}' d='M6,30H2V2h4V30z M12,2H8v28h4V2z M18,2h-4v28h4V2z M24,2h-4v28h4V2z M30,2h-4v28h4V2z'/>"
  296. + "</svg>";
  297. MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xml));
  298. var svg = SvgLoader.LoadFromStream(ms);
  299. ms.Dispose();
  300. return svg;
  301. }
  302. /// <summary>
  303. /// 导出图像图片
  304. /// </summary>
  305. /// <returns></returns>
  306. public static SvgImage CreateExportImg()
  307. {
  308. string xml = $"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox='0 0 32 32'>" + "<style type=\"text/css\">\r\n\t.Black{fill:#727272;}\r\n\t.Blue{fill:#1177D7;}\r\n\t.Red{fill:#D11C1C;}\r\n\t.st0{opacity:0.2;}\r\n</style>\r\n<path class=\"Black\" d=\"M8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.5-0.2-1.1l0,0\r\n\t\tc0,0.8,0.1,1.4,0.1,2v4.3h-1.4v-7.7h2.2l1.4,4.6c0.1,0.4,0.2,0.7,0.2,1.1l0,0c0.1-0.4,0.2-0.8,0.3-1.1l1.4-4.6H19v7.7H18.9z\r\n\t\t M26,17.3c-0.7,0.4-1.5,0.7-2.5,0.7c-1.1,0-2-0.3-2.6-1S20,15.4,20,14.2s0.3-2.2,1-3s1.6-1.1,2.8-1.1c0.7,0,1.4,0.1,1.9,0.3V12\r\n\t\tc-0.5-0.3-1.2-0.5-1.9-0.5c-0.6,0-1.2,0.2-1.6,0.7s-0.6,1.1-0.6,1.9c0,0.8,0.2,1.4,0.5,1.8c0.4,0.4,0.8,0.6,1.5,0.6\r\n\t\tc0.4,0,0.7-0.1,0.9-0.2v-1.5h-1.4v-1.4H26V17.3z\"/>\r\n</g>"
  309. + "</svg>";
  310. MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xml));
  311. var svg = SvgLoader.LoadFromStream(ms);
  312. ms.Dispose();
  313. return svg;
  314. }
  315. /// <summary>
  316. /// 导出Excel图片
  317. /// </summary>
  318. /// <returns></returns>
  319. public static SvgImage CreateExportXlsx()
  320. {
  321. string xml = $"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox='0 0 32 32'>" + "<style type=\"text/css\">\r\n\t.Green{fill:#039C23;}\r\n\t.Black{fill:#727272;}\r\n\t.Blue{fill:#1177D7;}\r\n\t.st0{opacity:0.3;}\r\n</style>\r\n<path class=\"Black\" d=\"M8,4h18v6h2V3c0-0.5-0.5-1-1-1H7C6.5,2,6,2.5,6,3v7h2V4z\"/>\r\n<path class=\"Black\" d=\"M26,28H8V18H6v11c0,0.5,0.5,1,1,1h20c0.5,0,1-0.5,1-1V18h-2V28z\"/>\r\n<path class=\"Green\" d=\"M31,8H3C2.4,8,2,8.4,2,9v10c0,0.6,0.4,1,1,1h28c0.6,0,1-0.4,1-1V9C32,8.4,31.6,8,31,8z M9.1,18l-1.3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.2-0.3,0.4-0.5,0.7-0.7c0.3-0.2,0.6-0.3,1-0.4s0.8-0.1,1.2-0.1c0.4,0,0.8,0,1.1,0.1c0.3,0,0.6,0.1,0.9,0.2\r\n\t\tv1.6c-0.1-0.1-0.3-0.2-0.4-0.2s-0.3-0.1-0.5-0.2c-0.2,0-0.3-0.1-0.5-0.1s-0.3,0-0.5,0s-0.4,0-0.5,0.1c-0.2,0-0.3,0.1-0.4,0.2\r\n\t\tc-0.1,0.1-0.2,0.1-0.3,0.2c-0.1,0.1-0.1,0.2-0.1,0.3s0,0.2,0.1,0.3s0.2,0.2,0.3,0.3c0.1,0.1,0.3,0.2,0.5,0.3s0.4,0.2,0.6,0.3\r\n\t\tc0.3,0.1,0.6,0.3,0.8,0.4c0.2,0.1,0.5,0.3,0.6,0.5c0.2,0.2,0.3,0.4,0.4,0.6s0.1,0.5,0.1,0.8C22.6,16.3,22.5,16.6,22.4,16.9z\r\n\t\t M28.1,18l-1.3-2.5c-0.1-0.1-0.1-0.3-0.2-0.5l0,0c0,0.1-0.1,0.3-0.2,0.5L25.1,18H23l2.5-3.9l-2.2-3.9h2.1l1.1,2.3\r\n\t\tc0.1,0.2,0.2,0.4,0.2,0.7l0,0c0-0.2,0.1-0.4,0.2-0.7l1.2-2.3H30L27.7,14l2.4,3.9L28.1,18L28.1,18z\"/>\r\n</g>"
  322. + "</svg>";
  323. MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xml));
  324. var svg = SvgLoader.LoadFromStream(ms);
  325. ms.Dispose();
  326. return svg;
  327. }
  328. /// <summary>
  329. /// 导出Csv图片
  330. /// </summary>
  331. /// <returns></returns>
  332. public static SvgImage CreateExportCsv()
  333. {
  334. string xml = $"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox='0 0 32 32'>" + "<style type=\"text/css\">\r\n\t.Black{fill:#727272;}\r\n\t.Blue{fill:#1177D7;}\r\n</style>\r\n<path class=\"Black\" d=\"M8,4h18v6h2V3c0-0.5-0.5-1-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0.1,1.1-0.1c0.4,0,0.7,0,1,0.1\r\n\tc0.3,0,0.6,0.1,0.8,0.2v1.6c-0.1-0.1-0.3-0.2-0.4-0.2c-0.1-0.1-0.3-0.1-0.4-0.2c-0.1,0-0.3-0.1-0.4-0.1c-0.1,0-0.3,0-0.4,0\r\n\tc-0.2,0-0.3,0-0.5,0.1c-0.1,0-0.3,0.1-0.4,0.2c-0.1,0.1-0.2,0.1-0.2,0.2c-0.1,0.1-0.1,0.2-0.1,0.3c0,0.1,0,0.2,0.1,0.3\r\n\tc0.1,0.1,0.2,0.2,0.3,0.3c0.1,0.1,0.3,0.2,0.4,0.3c0.2,0.1,0.4,0.2,0.6,0.3c0.3,0.1,0.5,0.3,0.8,0.4c0.2,0.1,0.4,0.3,0.6,0.5\r\n\tc0.2,0.2,0.3,0.4,0.4,0.6c0.1,0.2,0.1,0.5,0.1,0.8C19.5,16.1,19.4,16.5,19.2,16.8z M26,13.2l-1.5,4.7h-1.8L20.3,10H22l1.5,5.5\r\n\tc0.1,0.3,0.1,0.5,0.1,0.8h0c0-0.2,0.1-0.5,0.2-0.8l1.5-5.5H26h1L26,13.2z\"/>"
  335. + "</svg>";
  336. MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xml));
  337. var svg = SvgLoader.LoadFromStream(ms);
  338. ms.Dispose();
  339. return svg;
  340. }
  341. }
  342. }