C# WebApi生成SVG图

 1 public HttpResponseMessage CreateUserLogo(string realName)
 2 {
 3             var httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK)
 4             {
 5                 Content = new StringContent(
 6                 $"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" id=\"Layer_1\" x=\"0px\" y=\"0px\" viewBox=\"0 0 500 500\" enable-background=\"new 0 0 500 500\" xml:space=\"preserve\" height=\"500px\" width=\"500px\"><rect width=\"500\" height=\"500\" fill=\"#A8F0A8\"/><text x=\"50%\" y=\"50%\" dy=\".3em\" font-family=\"sans-serif\" font-size=\"220px\" text-anchor=\"middle\" fill=\"#330000\">{realName}</text></svg>", Encoding.UTF8)
 7             };
 8             httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("image/svg+xml");
 9             httpResponseMessage.Content.Headers.ContentType.CharSet = "UTF-8";
10             return httpResponseMessage;
11 }

 

效果图

 

 

posted @ 2020-06-10 16:35  煮不熟的鸭子  阅读(1271)  评论(0编辑  收藏  举报