如何从 TypeScript 的资源中获取 NativeScript 图像?

How to get NativeScript image from resources in TypeScript?

在模板中,我可以获得如下图像:res:imageName

如何从打字稿代码中获取图像?只需指定资源文件的完整路径?

代码上也是一样的。 res://image 在你的 html

<Image [src]="getImageSource(logo_white_bg)" stretch="none" class="img-rounded p-l-15 p-r-15 p-t-15"></Image>

如果您想将图像保存在特定文件夹中(例如 'logos'),以便 ios 在你的 .ts 文件中

getImageSource(icon: string) {
        return isAndroid ? `res://${icon}` : 'res://logos/' + icon;
    }