Ionic call local camera to take photos

Source: Internet
Author: User
Tags base64
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

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.