public ActionResult Upload(HttpPostedFileBase book) { HttpPostedFileBase bookImage = null; if (Request.Files.Count == 0) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } else { bookImage = Request.Files[0]; } if (bookImage != null && (bookImage.ContentType == "image/jpeg" || bookImage.ContentType == "image/jpg" || bookImage.ContentType == "image/png")) { string fileName = bookImage.FileName; System.Drawing.Image image = System.Drawing.Image.FromStream(bookImage.InputStream); Bitmap bmp = new Bitmap(image); string result = Ocr.Doit(bmp).Trim(); if (result == null) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } string[] words = result.Split(' '); List <string> wordList = words.ToList(); string isbn = wordList[wordList.Count - 1]; wordList.RemoveAt(wordList.Count() - 1); string name = string.Join(" ", wordList.ToArray()); return(Json(new { name = name, isbn = isbn }, JsonRequestBehavior.AllowGet)); } return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); }
public ActionResult Upload(HttpPostedFileBase book) { HttpPostedFileBase bookImage = null; if (Request.Files.Count == 0) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } else { bookImage = Request.Files[0]; } if (bookImage != null && (bookImage.ContentType == "image/jpeg" || bookImage.ContentType == "image/jpg" || bookImage.ContentType == "image/png")) { string fileName = bookImage.FileName; System.Drawing.Image image = System.Drawing.Image.FromStream(bookImage.InputStream); Bitmap bmp = new Bitmap(image); string result = Ocr.Doit(bmp).Trim(); if (result == null) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } return(Json(new { isbn = result }, JsonRequestBehavior.AllowGet)); } return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); }