Tôi đang sử dụng plugin jquery webcam trong trang MVC4. Plugin có tại đây: http://www.xarg.org/project/jquery-webcam-plugin/.Plugin jquery webcam không đăng hình ảnh được chụp
Tôi đang sử dụng phương pháp lưu trên plugin sau khi chụp hình nhưng không được đăng lên hành động của bộ điều khiển.
Đây là trang cshtml:
@{
ViewBag.Title = "Index";
}
<!DOCTYPE html>
<html lang="es">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>@ViewBag.Title - Prueba WebCam</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/styles/base")
@Scripts.Render("~/scripts/jquery", "~/scripts/jqueryui", "~/scripts/webcam")
<script type="text/javascript">
$(function() {
$("#camera").webcam({
width: 320,
height: 240,
mode: "save",
swffile: "@Url.Content("~/Scripts/WebCam/jscam_canvas_only.swf")",
onTick: function() { },
onSave: function() { alert('Almacenamiento realizado') },
onCapture: function() { webcam.save("@Url.Action("Save")"); alert('Captura realizada'); },
debug: function() { },
onLoad: function() { }
});
});
function CaptureAndSave() {
webcam.capture();
}
</script>
</head>
<body class="home desytec">
<header>
</header>
<!-- MAIN -->
<div id="main">
<!-- wrapper-main -->
<div class="wrapper">
<!-- headline -->
<div class="clear"></div>
<div id="headline">
<span class="main"></span>
<span class="sub"></span>
</div>
<!-- ENDS headline -->
<!-- content -->
<div id="content">
<div id="camera"></div>
<br /><br /><br />
<input type="button" onclick="CaptureAndSave();" value="Capturar" />
</div>
<!-- ENDS content -->
</div>
<!-- ENDS wrapper-main -->
</div>
<!-- ENDS MAIN -->
<footer>
</footer>
</body>
</html>
Và đây là bộ điều khiển:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Capture.Controllers
{
public class CaptureController : Controller
{
//
// GET: /Capture/
public ActionResult Index()
{
return View();
}
[HttpPost]
public JsonResult Save(HttpPostedFileBase file)
{
try
{
if (file != null)
{
string pic = System.IO.Path.GetFileName(file.FileName);
string path = System.IO.Path.Combine(Server.MapPath("~/Captures"), pic);
file.SaveAs(path);
return Json(true, JsonRequestBehavior.AllowGet);
}
}
catch
{
}
return Json(true, JsonRequestBehavior.AllowGet);
}
}
}
phương thức Save của bộ điều khiển được bao giờ gọi và trên thực tế, bằng cách sử dụng con đom đóm, không POST được thực hiện .
Nhân tiện. Máy ảnh hoạt động vì tôi có thể nhìn thấy nó trong canvas (DIV id = camera).
Và gọi lại OnCapture được gọi sau khi tôi nhấn nút chụp.
Bất kỳ trợ giúp nào về điều này, vui lòng?
Cảm ơn Jaime
Bạn có thể giúp tôi ra .. Bạn có thể thực hiện một bài đăng thông thường để lưu hành động hay không. Hãy để nó được viết theo cách của nó, và sử dụng cURL hoặc một số phần mở rộng của trình duyệt của bạn để đăng một số dữ liệu về hành động và xem bạn có bị trúng không? –
Nemesv ... xin lỗi .. Tôi sẽ kiểm tra giải pháp khi tôi về nhà sau khoảng 3 giờ. Trân trọng. – jstuardo