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 }

 

效果圖

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM