ttmind

Main Navigation

ttmind
  • jim-jams
  • Tech
  • Positive
Login

Login

Facebook Google

OR

Remember me Forgot password?

Don't have account? Signup here.

Sort by Categorys

.Net

PHP

Java

JavaScript

Database

Server

Client Side

Tools

Artificial Intelligence

Cloud

Hybrid Development

Event

Smart City

Education

Security

Scrum

Digital Marketing

APP Development

Business

Internet

Simulation

Art

Network

Microservices

Architecture

Technology

Leadership

    Top Articles

  • How Does Social Media Bring People Together?
    TTMind Author
  • How to read appSettings JSON from Class Library in ASP.NET Core
    Anil Shrestha
  • Printing Support In Asp.Net Core
    TTMind Author
  • HOW TO EXTRACT TEXT FROM IMAGE USING JAVASCRIPT (OCR with Tesseract.js)?
    Prakash Pokhrel
  • Images Upload REST API using ASP.NET Core
    Prakash Pokhrel
  • Related Topic

  • Firebase Cloud Messaging (FCM) using Cordova FCM Plugin
  • Cordova Upload Images using File Transfer Plugin and .Net core WebAPI
  • How to get Current user Location from device in ionic Cordova?
  • Could not find gradle wrapper within Android SDK. Might need to update your Android SDK. Looked here: Local\Android\Sdk\tools\templates\gradle\wrapper
  • What is ionic? How to start mobile app development with ionic?
  • Tech
  • About Us
  • Contact Us
  • TechHelp
  • PositiveHelp
  • Jim-Jams Help
  • Terms & Conditions

© Copyright ttmind.com

Main Content

Capture and load Image in Cordova

Hybrid Development Cordova about 7 years ago || 6/10/2018 || 3.1 K View

  • Hide

1. Create New Cordova Project on Visual Studio.
2. Go to Config.xml 
3. Go to Plugins
4. In core, you can find  Camera plugin (cordova-plugin-camera) and click on add.

you can see your installed plugin on config.xml (code view).

<plugin name="cordova-plugin-camera" spec="~2.4.1" />

5. Add one Button and one Div on your index.html

<input type="button" id="TakePhoto" value="Take Photo"/>
<div id="ViewPhoto"></div>

6.In Index.js, create Click Event on TakePhoto Button and add following code.
 

document.getElementById('TakePhoto').onclick = function () {
  navigator.camera.getPicture(function (imageUri) {
    var CapturePhoto = document.getElementById("ViewPhoto");
    alert("Photo Captured");
    CapturePhoto.innerHTML = "<img class='fit' src="+imageUri+" 'style' />";
    }, null, null);
   };

Output:

 

Final "Index.html" is here

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
        <link rel="stylesheet" type="text/css" href="css/index.css">
        <title>CameraApp</title>
    </head>
    <body>
       <input type="button" id="TakePhoto" value="Take Photo"/>
        <div id="ViewPhoto"></div>        
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="scripts/platformOverrides.js"></script>
        <script type="text/javascript" src="scripts/index.js"></script>
    </body>
</html>

and Final "Index.js" is here

(function () {
    "use strict";
    document.addEventListener('deviceready', onDeviceReady.bind(this), false);
    function onDeviceReady() {
        var parentElement = document.getElementById('deviceready');
        document.getElementById('TakePhoto').onclick = function () {
            navigator.camera.getPicture(function (imageUri) {
                var CapturePhoto = document.getElementById("ViewPhoto");
                alert("Photo Captured");
                CapturePhoto.innerHTML = "<img class='fit' src="+imageUri+" 'style' />";
            }, null, null);
        };        
    };    
} )();

 

  • 3
  • 0
  • 0
    • Facebook
    • Twitter
    • Google +
    • LinkedIn

About author

Prakash Pokhrel

Prakash Pokhrel

https://np.linkedin.com/in/prakash-pokhrel-42a699a2

Reset Your Password
Enter your email address that you used to register. We'll send you an email with your username and a link to reset your password.

Quick Survey