【发布时间】:2014-04-02 21:10:24
【问题描述】:
我想将 base64 图像从我的视图发送到控制器 这是我的视图代码
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
<img width="60" height="60" alt="" src="data:image/jpeg;base64,....."/>
@Html.TextArea("resultText")
<input type="submit" style="margin-left:40px;cursor:pointer;" id="l" value="Envoyer"/>
}
在我的控制器中,我想在参数中获取图像 这是控制器的代码
public ActionResult Index(HttpPostedFileBase imageFile)
{
//Conversion
if (imageFile!= null && imageFile.ContentLength > 0)
{
// for now just fail hard if there's any error however in a propper app I would expect a full demo.
using (var engine = new TesseractEngine(Server.MapPath(@"./tessdata"), "eng", EngineMode.Default))
{
// have to load Pix via a bitmap since Pix doesn't support loading a stream.
using (var image = new System.Drawing.Bitmap(imageFile.InputStream))
{
using (var pix = PixConverter.ToPix(image))
{
using (var page = engine.Process(pix))
{
//meanConfidenceLabel.InnerText = String.Format("{0:P}", page.GetMeanConfidence());
//ViewBag.meanConfidenceLabel = String.Format("{0:P}", page.GetMeanConfidence());
ViewBag.resultText = page.GetText();
}
}
}
}
}
return View();
}
上面的方法在参数中接受一个上传的图像,但我想要一个 base64 图像。 我试图通过传递 src 的值将其作为字符串获取,但它不起作用。
【问题讨论】:
标签: c# image asp.net-mvc-4 razor