英文:
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中,我看到了这个错误:
英文:
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("loading");
const options: ModalDialogOptions = {
context: imageAsset,
viewContainerRef: this.vref,
fullscreen: false
};
setTimeout(async () => {
const response = await this.modal.showModal(
ConfirmImageComponent,
options
);
if (response == "success") {
}
});
}
Service:
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;
}
}
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:
答案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<any> {
let context = imagepicker.create({
mode: "single"
});
await context.authorize();
const selection = await context.present();
return selection[0];
}
Make sure you catch the errors from select photo.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论