|
源代码分享给你 希望对你有帮助,下面代码是经过测试的 肯定能用,使用的时候主意引入文件路径
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>phonegap_device_network_notification01</title>
- <link href="../jquery.mobile-1.3.2.css" rel="stylesheet" type="text/css"/>
- <script src="../jquery.js" type="text/javascript"></script>
- <script src="../jquery.mobile-1.3.2.js" type="text/javascript"></script>
- <script src="../cordova.js" type="text/javascript"></script>
- <style >
- .imageContainer
- {
- width: 288px;
- height: 288px;
- position: relative;
- background-color: #fbfbfb;
- border: 1px solid #b8b8b8;
- }
- #myImage
- {
- max-width: 288px;
- max-height: 288px;
- display:block;
- }
- </style>
- <script type="text/javascript" charset="utf-8">
-
- $(document).ready(function(){
-
- document.addEventListener("deviceready",onDeviceReady,false);
-
- });
- function onDeviceReady()
- {
- console.log("deviceReady");
- $( ".captureBtn" ).bind( "click", function(event, ui) {
- getPictureFromCamera();
-
- });
- $( ".browserBtn" ).bind( "click", function(event, ui) {
- getPictureFromePhotoLibrary();
-
- });
- }
-
- function getPictureFromCamera()
- {
- navigator.camera.getPicture(onSuccess, onFail, { quality: 50,destinationType: Camera.DestinationType.DATA_URL,sourceType:navigator.camera.PictureSourceType.CAMERA});
- }
-
- function onSuccess(imageData) {
- var image = document.getElementById('myImage');
- image.src = "data:image/jpeg;base64," + imageData;
- }
- function onFail(message) {
- alert('Failed because: ' + message);
- }
-
-
-
- function getPictureFromePhotoLibrary()
- {
- navigator.camera.getPicture(onSuccessFromLib, onFail, { allowEdit:true,quality: 90,destinationType:Camera.DestinationType.FILE_URI ,sourceType:navigator.camera.PictureSourceType.PHOTOLIBRARY});
- function onSuccessFromLib(imageURI)
- {
- alert("imageURI"+imageURI);
- var image = document.getElementById('myImage');
- image.src = imageURI;
- }
- }
- </script>
- </head>
- <body>
- <div data-role="page">
- <div data-role="header">
- <h1>Camera</h1>
- </div>
- <div data-role=content>
- <a data-role="button" data-transition="fade" class="captureBtn" >拍照 </a>
- <a data-role="button" data-transition="fade" class="browserBtn">浏览 </a>
- <div class="imageContainer">
- <img id="myImage" />
- </div>
- </div>
- <div data-role="footer">
- <h4> </h4>
- </div>
- </div>
- </body>
- </html>
复制代码
转载请注明出处: phonegap中文网(www.phonegap100.com)
|
|