【问题标题】:ImageSource from base64 string in Nativescript来自 Nativescript 中 base64 字符串的 ImageSource
【发布时间】:2017-09-15 13:52:03
【问题描述】:

我完全不知道如何从 base64 字符串创建 ImageSource

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

在这种情况下,以下承诺中传递的参数是一个布尔值,我不知道它应该代表什么。之后的 ImageSource 在 android 和 iOS 上都是 null。

我在这里错过了什么?

【问题讨论】:

    标签: base64 nativescript imagesource


    【解决方案1】:

    我加载它并像这样放入一个 Image 元素:

    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)

    【讨论】:

    • 显然我的错误是在 base64 字符串中有 mimetype,它返回 false。将您标记为答案,因为它是关于如何使用 ImageSource 类的一个很好的代码示例。
    猜你喜欢
    • 1970-01-01
    • 2014-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-25
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多