documentation में कई उदाहरण हैं। जो कुछ भी जरूरी है उसे पढ़ना और कोशिश करना है।
<script src="@Url.Content("~/Scripts/jquery.webcam.js")" type="text/javascript"></script>
<div id="webcam"></div>
<a href="#" id="upload">Capture image and send for processing</a>
<script type="text/javascript">
var pos = 0, ctx = null, saveCB, image = [];
var canvas = document.createElement('canvas');
canvas.setAttribute('width', 320);
canvas.setAttribute('height', 240);
ctx = canvas.getContext('2d');
image = ctx.getImageData(0, 0, 320, 240);
var saveCB = function (data) {
var col = data.split(';');
var img = image;
for (var i = 0; i < 320; i++) {
var tmp = parseInt(col[i]);
img.data[pos + 0] = (tmp >> 16) & 0xff;
img.data[pos + 1] = (tmp >> 8) & 0xff;
img.data[pos + 2] = tmp & 0xff;
img.data[pos + 3] = 0xff;
pos += 4;
}
if (pos >= 4 * 320 * 240) {
ctx.putImageData(img, 0, 0);
$.post('@Url.Action("Upload")', { type: 'data', image: canvas.toDataURL("image/png") }, function (result) {
if (result.success) {
alert('The image was successfully sent to the server for processing');
}
});
pos = 0;
}
};
$('#webcam').webcam({
width: 320,
height: 240,
mode: 'callback',
swffile: '@Url.Content("~/scripts/jscam_canvas_only.swf")',
onSave: saveCB,
onCapture: function() {
webcam.save();
}
});
$('#upload').click(function() {
webcam.capture();
return false;
});
</script>
:
तो यहाँ अपने Index.cshtml
दृश्य ब्राउज़र की HTML5 कैनवास तत्वों का उपयोग कर कच्चे छवि एक PNG छवि है कि एक AJAX अनुरोध का उपयोग कर सर्वर पर भेज दिया जाएगा में वेब कैमरा से आने वाले डेटा एन्कोड करने के लिए कैसा लग सकता है तरीका बताया गया है
और अपने घर नियंत्रक:
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Upload(string image)
{
image = image.Substring("data:image/png;base64,".Length);
var buffer = Convert.FromBase64String(image);
// TODO: I am saving the image on the hard disk but
// you could do whatever processing you want with it
System.IO.File.WriteAllBytes(Server.MapPath("~/app_data/capture.png"), buffer);
return Json(new { success = true });
}
}
स्रोत
2012-02-26 09:36:59
क्या आप इस वेब ऐप को बनाने में सफल हुए हैं जो बारकोड पढ़ने के लिए सर्वर पर एक फोटो और अपलोड करता है? मैं बिल्कुल वही काम करने वाला हूं और परेशानी है –
हाँ, मुझे चांदी की रोशनी का उपयोग करके कुछ सीमित सफलता मिली है। छवि को पढ़ने में सक्षम, लेकिन वास्तविक बार कोड पढ़ने में बहुत समय था, शायद एक बेहतर वेबकैम की आवश्यकता है। – nagates
लेकिन चांदी की रोशनी एंड्रॉइड और आईओएस पर काम नहीं करती है! तो आपका वेब ऐप एंड्रॉइड और आईओएस उपकरणों के लिए नहीं है? –