setNativeSource()方法需要android.graphics.Bitmap实例。

huangapple go评论83阅读模式
英文:

The method setNativeSource() expects android.graphics.Bitmap instance

问题

在我的应用程序中,如果我从图库选择一张图片,我必须被重定向到一个包含该图片的模态窗口。问题是,图片从服务下载到组件中,但没有显示,而是显示了错误消息。

从中发送请求到图库的组件:

        const imageAsset = await this.gallery.selectPhoto();
        this.rediresct("loading");
        const options: ModalDialogOptions = {
            context: imageAsset,
            viewContainerRef: this.vref,
            fullscreen: false
        };
        setTimeout(async () => {
            const response = await this.modal.showModal(
                ConfirmImageComponent,
                options
            );
            if (response == "success") {
            }
        });
    }

服务:

    
    source: any;
    constructor() {}
    async selectPhoto(): Promise<Array<any>> {
        let context = imagepicker.create({
            mode: "single"
        });
        await context.authorize();
        let imageAsset = [];
        const selection = await context.present();
      

        imageAsset = selection;
        return imageAsset;
    }
}

从服务下载图片并应该显示的组件:

    obraz: ImageAsset;
    constructor(
        private gallery: GalleryService,
        private params: ModalDialogParams
    ) {
        this.image = params.context;

        var pict = new Image();
        pict.src = this.image;
        console.log(pict.src);
    }

    ngOnInit() {}
} 

在最后的代码中,我使用控制台日志来显示选定的图片来源,它可以正常工作,但图片没有显示出来。在VS Code中,我看到了这个错误:
setNativeSource()方法需要android.graphics.Bitmap实例。

英文:

In my application, if I choose an image from the gallery, I have to be redirected to a modal window with that image. The problem is that the image is downloaded from the service to the component, but is not displayed, instead I have an error message.

The component from which I send my request to the gallery:

        const imageAsset = await this.gallery.selectPhoto();
        this.rediresct(&quot;loading&quot;);
        const options: ModalDialogOptions = {
            context: imageAsset,
            viewContainerRef: this.vref,
            fullscreen: false
        };
        setTimeout(async () =&gt; {
            const response = await this.modal.showModal(
                ConfirmImageComponent,
                options
            );
            if (response == &quot;success&quot;) {
            }
        });
    }

Service:

    
    source: any;
    constructor() {}
    async selectPhoto(): Promise&lt;Array&lt;any&gt;&gt; {
        let context = imagepicker.create({
            mode: &quot;single&quot;
        });
        await context.authorize();
        let imageAsset = [];
        const selection = await context.present();
      

        imageAsset = selection;
        return imageAsset;
    }
}

The component that downloads the image from the service and has to display it:

    obraz: ImageAsset;
    constructor(
        private gallery: GalleryService,
        private params: ModalDialogParams
    ) {
        this.image = params.context;

        var pict = new Image();
        pict.src = this.image;
        console.log(pict.src);
    }

    ngOnInit() {}
} 

In last code I use console log to display selected image source and it works, but image is not displayed. In VS Code I see this error:
setNativeSource()方法需要android.graphics.Bitmap实例。

答案1

得分: 2

为了返回单个资产,你可以这样做,

async selectPhoto(): Promise<any> {
    let context = imagepicker.create({
        mode: "single"
    });
    await context.authorize();
    const selection = await context.present();
    return selection[0];
}

确保捕获来自选择照片的错误。

英文:

To return a single asset you could just do,

async selectPhoto(): Promise&lt;any&gt; {
    let context = imagepicker.create({
        mode: &quot;single&quot;
    });
    await context.authorize();
    const selection = await context.present();
    return selection[0];
}

Make sure you catch the errors from select photo.

huangapple
  • 本文由 发表于 2020年1月3日 18:05:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/59576567.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定