Help with Image load


I’m trying to load and display a previously image saved as base64 (:nativescript: + :nng:).

Simplified Component:

import { takePicture, requestPermissions } from "nativescript-camera";
import { RouterExtensions } from "nativescript-angular/router";

import { Component, OnInit, NgZone, ViewChild, ElementRef } from "@angular/core";

import { Page } from "ui/page";
import { Image } from "ui/image";

import { ImageSource } from "image-source";

	selector: "ns-vistoria",
	templateUrl: "./os-vistoria.component.html",
	styleUrls: ["./os-vistoria-common.css"]
export class OSVistoriaComponent implements OnInit {
	vistoria: OrdemServicoVistoria;
	imageSource: ImageSource;
	fotoVistoria: Image;
	 @ ViewChild("fotoVistoria")fotoVistoriaImage: ElementRef;

		private page: Page,
		private zone: NgZone,
		private routerExtensions: RouterExtensions) {}

	ngOnInit() {
		this.vistoria = ...;

    ngAfterViewInit() {

	initPhoto() {
		console.log('********************************************** initPhoto() **********************************************');
		if (!this.vistoria.photobase64) {

		let imageSource = new ImageSource();

		.then(res => {
			if (res) { => {
					let fotoVistoria =  < Image > this.fotoVistoriaImage.nativeElement;
					fotoVistoria.imageSource = imageSource;
					this.fotoVistoria = fotoVistoria;
					this.fotoVistoria.imageSource = imageSource;


Simplified Page:

<StackLayout orientation="vertical">
	<Image #fotoVistoria stretch="none" horizontalAlignment="center" verticalAlignment="center"></Image>

Nothing happens (nor errors); res in my trial is true and I manage to save and display the picture taken in a similar way, the first time I take the picture.

Any ideas?



Try using <Image [src]="imageSrc"></Image>

I guess in your case fotoVistoria.src = imageSource;

I struggled and finally got this working, but then started getting out of memory errors on android when using imagesource. So even when you think it’s working I recommend doing some tests to make sure the garbage collector does it’s thing correctly. I’m still stuck at that part :frowning:


What is imageSrc in this case?


An ImageSource…

public imageSrc: ImageSource;

and in my constructor I have something like:

let folder = fs.knownFolders.documents();
this.imageSrc = imageSource.fromFile(fs.path.join(folder.path, `${this.individual.species.genus}_${this.individual.species.species}.png`));


If you’re getting OOM issues - I’d switch to using Fresco for android - just wrap the UI in <android> <frescoStuff></android <ios> <Image /></ios> takes a bit more work but 99.9999% of the time you won’t have OOM issues on android @jeffswitzer


Thanks Brad! Was beginning to think I was at a dead end but hadn’t seen nativescript-fresco. I’ll take it for a test run tomorrow.


Hey @jeffswitzer, I tried something like your suggestion, no luck. My last trial:

<Image #fotoVistoria stretch="none" horizontalAlignment="center" verticalAlignment="center"  [src]="imageSource"></Image>
initPhotos() {
        console.log('********************************************** initPhotos() **********************************************');
        if (!this.vistoria.fotoVistoria) {
        } => {
            this.imageSource = new ImageSource();


Have you ran a debugger on that code or stuck a console log inside the callback? I see that you return out of the function if this.vistoria.fotoVistoria doesn’t exist. I’d check to make sure that the new ImageSource() code is actually getting called. Also another test you can run is instead of [src]=“imageSource” try [src]=“http path to some image” and see if that even shows up.


Nice suggestion, @jeffswitzer!
So, entering the URL of an image, it’s not displayed too:

<StackLayout orientation="vertical">
	<Label text="Foto da Vistoria" class="label-title"></Label>
	<GridLayout columns="auto, *, auto">
		<StackLayout orientation="vertical" col="0" (tap)="tirarFoto($event)" verticalAlignment="center">
			<Label class="mdi tirarFotoIco" [text]="'mdi-camera-enhance' | fonticon" horizontalAlignment="center"></Label>
			<Label class="small-font underline-text" [text]="'Tirar foto'" horizontalAlignment="center"></Label>
		<Image #fotoVistoria stretch="none" horizontalAlignment="center" verticalAlignment="center" col="1"
		<Label class="mdi apagarFotoIco" padding="10" [text]="'mdi-delete-forever' | fonticon" horizontalAlignment="center" verticalAlignment="center"
			(tap)="removerFotoVistoria()" [visibility]="fotoVistoria.imageSource ? 'visible' : 'collapse'"

The result:

No errors. I commented out that initPhotos() part, to don’t invalidate the test.
Do you see anything wrong or what more could I check?



Oops, I lied. Some seconds after, this error comes:
Error in downloadBitmap - Connection refused


@jeffswitzer my mistake.
Emulator is not reaching internet. So I putted an URL of an internal address and the image is displayed.


About the other test:

initPhotos() {
        console.log('********************************************** initPhotos() **********************************************');
        if (!this.vistoria.fotoVistoria) {
        } => {
            console.log('zone code ');
            this.imageSource = new ImageSource();
            var loadedBase64 = this.imageSource.loadFromBase64(this.vistoria.fotoVistoria);


JS: zone code
JS: true


Suggestions anyone? @jen.looper? Didn’t manage to solve it yet :frowning:


Seems it was a bug reported in an issue.
So I upgraded my project following these instructions, from 3.0 to 3.1.1 (latest), and now the image is being displayed!

Thanks for the attention and help.


Glad it worked out. Also wanted to report that @bradwaynemartin suggestion to use nativescript-fresco really helped solve android oom errors I was getting related to loading images from disk.


If you do android apps and display any images, first plugin to go for is fresco :smiley: glad it helped, not everyone knows about it. Need to see if the core docs mention using fresco on the images section, if not a PR to mention it would be sweet.