[英]creating an Image from SVG on the server using asp.net MVC?
I am trying to create an image from an svg that I pass into my controller from the client side. 我正在尝试通过从客户端传递到控制器的svg创建图像。
the svg is being passed in thourgh a posted form's hidden input. 该svg会在已发布表单的隐藏输入中传递。
Controller: 控制器:
[HttpPost, ValidateInput(false)]
public ActionResult GetChartImage(string svgString)
{
byte[] imageBytes;
var bytes = Encoding.ASCII.GetBytes(svgString);
using (var stream = new MemoryStream(bytes))
{
var svgDocument = SvgDocument.Open(stream);
var bitmap = svgDocument.Draw();
bitmap.Save(stream, ImageFormat.Png);
imageBytes = stream.ToArray();
}
return File(new MemoryStream(imageBytes), "image/png");
}
the problem is that when the process finishes the new webpage that was opened as a result of posting the form, doesn't show the produced image: 问题在于,当流程完成由于发布表单而打开的新网页时,不会显示生成的图像:
This is a version that is using GET 这是使用GET的版本
MyController: MyController:
[HttpGet]
public FileContentResult GetEmployeeImage()
{
byte[] image = byteArrayFromImage;
return new FileContentResult(image , "image/jpeg");
}
View: 视图:
<img src="@Url.Action("GetEmployeeImage", "MyController")" alt="avatar" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.