Home > Blockchain >  Ionic Capacitor ImagePicker change type to Base64 Format?
Ionic Capacitor ImagePicker change type to Base64 Format?

Time:12-23

I am building an app with Ionic (Angular based) and Capacitor Plugins (Camera Plugin). Now I want that the user can select up to 5 images from their gallery, so I used the Capacitor Image Picker (https://capacitorjs.com/docs/apis/camera#pickimages). And it works perfectly, but the type of the images is a webpath and not BASE64?! How can I change the type? With the GalleryImageOptions it is not possible I think?

THANK YOU FOR YOUR ANSWERS!

CodePudding user response:

This way you can get a base64 URL from the Image Picker.

The outputType: 1 ist the important thing. Type 1 is base64.

getImages() {
    this.imgArray = [];
    this.imagePicker.getPictures({ maximumImagesCount: 10, quality: 50, height: 210, width: 210, outputType: 1 }).then(results => {
        if(results.length > 0) {
          for (let i = 0; i < results.length; i  ) {
            this.imgArray.push(results[i]);
          }
          // this.getImageData();
        }
      },
      error => {
           .....
        });
  }
  • Related