Conversion of image asset


#1

I need to know how I can convert the image asset tobase64 in NS-vue
camera.takePicture(options).
then((imageAsset) => {
console.log(“Result is an image asset instance”);
var image = new Image();
image.src = imageAsset.toBase64String(“jpeg”, 100);
console.log("Image -> " + image.src);

      }).catch((err) => {
          console.log("Error -> " + err.message);
      });
},

This is what I did… but says tobase64String is not a function


#2

toBase64String is something available in ImageSource not ImageAsset. Use fromAsset method in ImageSource to covert ImageAsset.

Docs: https://docs.nativescript.org/api-reference/classes/image_source.imagesource#tobase64string


#3

so are you saying I should convert the imageAsset to ImageSource first, then use the tobase64String on ImageSource?


#4

Hello @manojdcoder… I have gotten how to use the toBase64String function, but I don’t wanna use that anymore, so what I’m doing now is saving the captured image into a destination folder, but I don’t know how I can get the image that was saved.
This is what I have.

  camera.takePicture(options).
      then((imageAsset) => {
        const imageSourceModule = require("tns-core-modules/image-source");
        const fileSystemModule = require("tns-core-modules/file-system");
          let documents = fileSystemModule.knownFolders.documents();
          let path = fileSystemModule.path.join(documents.path, "pic.png");
          const source = new imageSourceModule.ImageSource();
          source.fromAsset(imageAsset)
          .then((imageSource) => {
            imageSource.saveToFile(path, "png");
          }).catch((err) => {
                  console.log("Error -> " + err.message);
      });
      }).catch((err) => {
          console.log("Error -> " + err.message);
      });