Ionic native camera plugin allows us to take a picture using the device camera. In this apps we will be creating two buttons, one to take the photo using device camera and other is to load existing picture from the device album.
The screenshot of our apps.
What we will learn:
- Access the Cordova camera plugin to trigger camera picture and get the image back in the Base64 or URI format.
- Parse the Base64 data or URI on an img tag DOM object.
- Display the URI if it’s in the URI format.
Step 1: ionic start MyCamera blank
$ ionic cordova plugin add cordova-plugin-camera
$ npm install –save @ionic-native/camera
Step 3: Add the following code in home.html.
Once we load or capture a photo, we can use ion-toggle to display on/off of image url.
Step 4: Add the following code in home.ts