Go VS2015 Cordova Try-camera

Source: Internet
Author: User



This article transferred from: http://blog.csdn.net/greystar/article/details/47973837



1. Make sure the environment is OK, if there is an error, Ann download the relevant version of the Android SDK, I also toss a few days on this.












2. Create a default Cordova project, and add the relevant plug-in, in the project directory Open Config. ins will open the configuration interface, you can choose the camera plug-in, optional installation.


















3. Call



Note: You cannot set an event call in HTML



Open www\index.html, do a demo of the interface






<body> <p>hello, your application is ready!</p>



<!--Cordova Reference, which is added to the application when it is built. --<script src= "Cordova.js" ></script> <script src= "Scripts/platformoverrides.js" ></script >



<script src= "Scripts/index.js" ></script>//The following two lines are examples, others are the template comes with, do not need to be adjusted, can not directly control the event call < onclick= "" > &L T;input type= "button" value= "Call Camera" id= "Btntakecamera"/> &L T;/body>



Add JS call, here directly modify the Index.js


[JavaScript]View Plaincopyprint?



  1. Document.addeventlistener ("Deviceready", Ondeviceready, false);
  2. function Ondeviceready () {
  3. document.getElementById ("Btntakecamera"). onclick = Takecamera;
  4. Alert ("Device initialization is normal");
  5. }
  6. function Takecamera () {
  7. Navigator.camera.getPicture (onsuccess, Onfail, {
  8. QUALITY:50,
  9. DestinationType:Camera.DestinationType.DATA_URL,
  10. EncodingType:Camera.EncodingType.JPEG,
  11. TARGETWIDTH:100,
  12. TARGETHEIGHT:100,
  13. });
  14. }
  15. function onsuccess (imageData) {
  16. var image = document.getElementById (' takeimg ');
  17. IMAGE.SRC = "data:image/jpeg;base64," + imageData;
  18. }
  19. function Onfail (message) {
  20. Alert (' Failed because: ' + message);
  21. }


document.addEventListener ("deviceready", onDeviceReady, false);
function onDeviceReady () {
     document.getElementById ("btntakeCamera"). onclick = takeCamera;
     alert ("device initialization is normal");
}
function takeCamera () {
     navigator.camera.getPicture (onSuccess, onFail, {
         quality: 50,
         destinationType: Camera.DestinationType.DATA_URL,
         encodingType: Camera.EncodingType.JPEG,
         targetWidth: 100,
         targetHeight: 100,
     });
}
function onSuccess (imageData) {
     var image = document.getElementById (‘takeImg’);
     image.src = "data: image / jpeg; base64," + imageData;
}

function onFail (message) {
     alert (‘Failed because:‘ + message);
} 





Camera specific parameters in Plugins\cordova-plugin-camera \doc\zh\index.md detailed introduction, traditional help, we should all be able to understand.






Go VS2015 Cordova Try-camera


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.