First create a Ionic project, add the camera plugin
$ ionic Cordova Plugin Add Cordova-plugin-camera
$ npm Install--save @ionic-native/camera
Introducing Plug-ins in App.module
Then write the call function in the corresponding TS file
Getpicturebycamera () {Const Options:cameraoptions = {quality:100,//Picture quality destinationtype:this. Camera. DestinationType. File_uri,//return value of the format sourcetype:this. Camera. Picturesourcetype. CAMERA,//Set the source of the picture allowedit:true,//whether to allow editing encodingtype:this. Camera. Encodingtype. JPEG,//Select the encoding of the returned image file
Mediatype:this. Camera. MediaType. Picture,//Select media type, according to SourceType to determine whether savetophotoalbum:true//is saved to album after taking pictures}
This. Camera. Getpicture (Options). Then (Imageuri) => {//ImageData is either a base64 encoded string or a file URI//If It's base64://Let Base64imag E = ' data:image/jpeg;base64, ' + imagedata; This.images.unshift ({//Src:base64image//}) this. Images. Unshift ({Src:imageuri})}, (Err) => {//Handle error}); Emphasis: When writing a method, declare the component in Consture