cordova - Opening Camera Instance from a Web App -
is possible open camera instance web app?
i have web app. displays something, , want user able take picture , send
server. how can achieve this?
using cordova apis it's easy
check out following code sample:
js:
// button call function // capture photo function capturephoto() { // take picture using device camera , retrieve image base64-encoded string navigator.camera.getpicture(uploadphoto, onfail, { quality: 50, destinationtype: camera.destinationtype.file_uri }); } // button call function // select image gallery function getphoto(source) { // retrieve image file location specified source navigator.camera.getpicture(uploadphoto, onfail, { quality: 50, destinationtype: navigator.camera.destinationtype.file_uri, sourcetype: navigator.camera.picturesourcetype.photolibrary }); } function uploadphoto(imageuri) { //if wish display image on page in app // image handle var largeimage = document.getelementbyid('largeimage'); // unhide image elements largeimage.style.display = 'block'; // show captured photo // inline css rules used resize image largeimage.src = imageuri; var options = new fileuploadoptions(); options.filekey = "file"; var userid = '123456'; var imagefilename = userid + number(new date()) + ".jpg"; options.filename = imagefilename; options.mimetype = "image/jpg"; var params = new object(); params.imageuri = imageuri; params.userid = sessionstorage.loginuserid; options.params = params; options.chunkedmode = false; var ft = new filetransfer(); var url = "your_web_service_url"; ft.upload(imageuri, url, win, fail, options, true); } //success callback function win(r) { alert("image uploaded successfully!!"); } //failure callback function fail(error) { alert("there error uploading image"); } // called if bad happens. // function onfail(message) { alert('failed because: ' + message); } html:
<input name="button" type="button" onclick="capturephoto()" value="take photo"/> <input name="button" type="button" onclick="getphoto();" value="browse" /> hope helps.
Comments
Post a Comment