我正在尝试将html字符串从我的视图转换为图像。我能够将我的视图作为字符串,但无法将其转换为图像(base64string或字节数组)以将其返回。这是我的代码
/* Getting label design info */
LabelDesigner ObjModel = GetLabelDesignObject("Drug_Label");
/* Taking view's HTML */
string HTML = RenderRazorViewToString("~/Views/Folder/DrugLabel.cshtml", ObjModel);
.............
.............
.............
.............
public string RenderRazorViewToString(string ViewName, object Model)
{
string ReturnVal = string.Empty;
try
{
ViewData.Model = Model;
using (var sw = new System.IO.StringWriter())
{
var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, ViewName);
var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
viewResult.View.Render(viewContext, sw);
viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View);
return sw.GetStringBuilder().ToString();
}
}
catch (Exception ex)
{
/* Catch Exception Here */
log.Error("Error in Controller.cs, RenderRazorViewToString function: " + ex.Message);
}
return ReturnVal;
}
在这里,我可以获取视图的HTML,但是如何将该HTML字符串转换为jpg图像?