Search code examples
nativescript-angular

byte array image src nativescript


In nativescript(with angular) is there any way to set the src of an image from the response of a web api call that returns the image as byte array/base64? There is not to much documentation, and I need to see the html and .ts files from a simple example, I have no code to paste here now.


Solution

  • you need to first create ImageSource form base64 string and then assign that imageSource to Image Native Element.

    let imageSource = new ImageSource();
    let loadedSource64 = imageSource.loadFromBase64(BASE_64_STRING_FROM_API_CALL);
    if (loadedSource64 ) {
        let image= <Image>this.imageElement.nativeElement;
        image.imageSource = this.imageSource;
    }