使用PhoneGap调用Camera (android)

使用PhoneGap调用Camera (android)

效果图:
使用PhoneGap调用Camera (android)
 
使用PhoneGap调用Camera (android)
 
使用PhoneGap调用Camera (android)

(function(){
	$('#camera').live('pageshow',function(){
		$('#takePhotoBtn').bind('click',function(){
			navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
		    	destinationType: Camera.DestinationType.FILE_URI
		 	}); 
		});
		
		function onSuccess(src) {
		    $('#photo').attr('src',src);
		}
		
		function onFail(message) {
		    alert('Failed because: ' + message);
		}
	});
})();
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/website.css" />
        <title>Camera with PhoneGap</title>
    </head>
    <body>
    	<div id="camera" data-role="page">
		     <h3>使用PhoneGap调用相机(android)</h3>
		     <div>
		     	<img id="photo" style="margin-left:40%;height:80px;width:80px;border:1px solid #ccc;" 
		     	src="img/cordova.png"/>
		     </div>
		     <div>
		     	<a id="takePhotoBtn" data-role="button" data-theme="b">照相</a>
		     </div>
		</div>
        <script type="text/javascript" charset="utf-8" src="js/cordova-2.3.0.js"></script>
        <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
        <script type="text/javascript" charset="utf-8" src="js/jquery.mobile-1.2.0.min.js"></script>
        <script type="text/javascript" charset="utf-8" src="js/camera.js"></script>
    </body>
</html>

 
 

相关推荐