ImageSource from base64 string in Nativescript

1.6k views Asked by At

I can't figure out at all how to create an ImageSource from a base64 string.

let source = new ImageSource(); source.fromBase64('b64strhere').then(..);

in this context the parameter passed in the following promise is a boolean which I don't know what's supposed to represent. The ImageSource afterwards is null both on android and iOS.

What am I missing here?

1

There are 1 answers

1
Cesar On BEST ANSWER

I load it and put in an Image element like this:

this.imageSource = new ImageSource();
var loadedBase64 = this.imageSource.loadFromBase64(MY_BASE_64_STRING_PREVIOUSLY_SAVED);
console.log(loadedBase64);
if (loadedBase64) {
    let photo = <Image>this.photoImage.nativeElement;
    photo.imageSource = this.imageSource;
    this.photo = photo;
}

(NS 3.1)