I am trying to create an image from an svg that I pass into my controller from the client side.
the svg is being passed in thourgh a posted form's hidden input.
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
MyController:
[HttpGet]
public FileContentResult GetEmployeeImage()
{
byte[] image = byteArrayFromImage;
return new FileContentResult(image , "image/jpeg");
}
View:
<img src="@Url.Action("GetEmployeeImage", "MyController")" alt="avatar" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.