我正在使用 ionic 3 创建一个应用程序。该应用程序应该执行以下操作:从外部摄像头拍摄图像(它将作为文件 URL 返回),使用 sqllite 作为 base64 将其存储在本地数据库中。
这是我的尝试
takeImage(){
const fileTransfer: FileTransferObject = this.transfer.create();
this.takePicture().subscribe(data => {
this.wait(7000);
this.listFiles().subscribe(data => {
const url = data['results'].entries[0].fileUrl;
fileTransfer.download(url, this.file.dataDirectory + data['results'].entries[0].name).then((entry) => {
this.room.img = entry.toURL();
this.base64.encodeFile( entry.toURL()).then((base64File: string) => {
this.room.img = base64File;},
(err) => {
console.log(err);
});
}, (error) => {});
},
err => {console.log(err);});
},
err => {console.log(err);});
}
我已尝试显示 base64File
但它不起作用。
最佳答案
显示base64图片需要在组件中导入DomSanitizer,在构造函数中创建实例变量,代码如下
constructor(public _DomSanitizer: DomSanitizer)
<img class="one-image" *ngFor="let image of item; let i= index" style="height:120px;" [src]="_DomSanitizer.bypassSecurityTrustUrl(image.imgUrl)" #images (click)="imageOption(i,images,image.data,image.ext)"/>
关于javascript - 存储从外部摄像头拍摄的图像并将其存储在数据库中 - Ionic 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53318737/