Jquery Phonegap捕获图像,然后将其上载到REST webservice
我需要使用jquery mobile和Phonegap开发移动应用程序 要从摄像头捕获图像,然后将其上载到REST web服务, 使用WCF(.NET)或JAX-RS(Jersey)是否可以做到这一点Jquery Phonegap捕获图像,然后将其上载到REST webservice,jquery,web-services,cordova,mobile,Jquery,Web Services,Cordova,Mobile,我需要使用jquery mobile和Phonegap开发移动应用程序 要从摄像头捕获图像,然后将其上载到REST web服务, 使用WCF(.NET)或JAX-RS(Jersey)是否可以做到这一点 如果是,是否有这样做的示例/教程?通过使用phonegap,您可以从相机捕获图像,请查看 要在服务器上上载图像,请使用以下代码进行操作: <!DOCTYPE HTML> <html> <head> <title>Cordova</title> <link rel
如果是,是否有这样做的示例/教程?通过使用phonegap,您可以从相机捕获图像,请查看 要在服务器上上载图像,请使用以下代码进行操作:
<!DOCTYPE HTML>
<html>
<head>
<title>Cordova</title>
<link rel="stylesheet" href="style.css" media="screen" />
<script type="text/javascript" charset="utf-8" src="cordova-2.2.0.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript" charset="utf-8">
var pictureSource; // picture source
var destinationType; // sets the format of returned value
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
pictureSource = navigator.camera.PictureSourceType;
destinationType = navigator.camera.DestinationType;
}
</script>
</head>
<body>
<script type="text/javascript" charset="utf-8">
var myData = "";
$(document).ready(function() {
$("#getDataFromServer").click(function() {
var imageData = myData;
$.ajax({
type : "POST",
url : 'http://my.domain.name/saveImage.ashx',
data : {
image : imageData
},
beforeSend : function() {
$("#comment2").text("Start ajax " + imageData.length);
},
success : function(data) {
$("#comment2").text("Uploaded! " + data);
},
error : function(request, error) {
$("#comment2").text("Error! " + error);
}
});
});
})
function capturePhotoEdit(source) {
navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
quality : 50,
destinationType : destinationType.DATA_URL,
sourceType : source
});
}
function onFail(message) {
alert('Failed because: ' + message);
}
function onPhotoDataSuccess(imageData) {
console.log(imageData);
var smallImage = document.getElementById('smallImage');
smallImage.style.display = 'block';
smallImage.src = "data:image/jpeg;base64," + imageData;
myData = imageData;
$("#comment").text(imageData.length);
}
</script>
<h1>Hello World</h1>
<p>
<a href="#" onclick="capturePhotoEdit(pictureSource.PHOTOLIBRARY);">get
image</a>
</p>
<p>
<a href="#" id="getDataFromServer">send image</a>
</p>
<span id="comment2"></span>
<img style="display: none; width: 100px; height: 100px;"
id="smallImage" src="" />
<span id="imagename"></span>
<span id="comment"></span>
</body>
</html>
科尔多瓦
var pictureSource;//图像源
var destinationType;//设置返回值的格式
文件。添加的监听器(“deviceready”,OnDeviceraddy,false);
函数ondevicerady(){
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.destinationType;
}
var myData=“”;
$(文档).ready(函数(){
$(“#getDataFromServer”)。单击(函数(){
var-imageData=myData;
$.ajax({
类型:“POST”,
网址:'http://my.domain.name/saveImage.ashx',
数据:{
图像:图像数据
},
beforeSend:function(){
$(“#comment2”).text(“开始ajax”+imageData.length);
},
成功:功能(数据){
$(“#comment2”).text(“上传!”+数据);
},
错误:函数(请求、错误){
$(“#comment2”).text(“Error!”+Error);
}
});
});
})
函数capturePhotoEdit(源){
navigator.camera.getPicture(onPhotoDataSuccess、onFail、{
质量:50,
destinationType:destinationType.DATA\u URL,
sourceType:source
});
}
函数onFail(消息){
警报('失败原因:'+消息);
}
函数onPhotoDataSuccess(imageData){
控制台日志(imageData);
var smallImage=document.getElementById('smallImage');
smallImage.style.display='block';
smallImage.src=“数据:图像/jpeg;base64,”+imageData;
myData=图像数据;
$(“#注释”).text(imageData.length);
}
你好,世界