Javascript 存储从外部摄像头拍摄的图像,并将其存储在DB-3中
我正在使用ionic 3创建一个应用程序。该应用程序应该执行以下操作:从外部摄像头获取图像(它将以文件URL的形式返回),使用sqllite作为base64将其存储在本地数据库中 这是我的尝试Javascript 存储从外部摄像头拍摄的图像,并将其存储在DB-3中,javascript,typescript,ionic-framework,ionic3,base64,Javascript,Typescript,Ionic Framework,Ionic3,Base64,我正在使用ionic 3创建一个应用程序。该应用程序应该执行以下操作:从外部摄像头获取图像(它将以文件URL的形式返回),使用sqllite作为base64将其存储在本地数据库中 这是我的尝试 takeImage(){ const fileTransfer: FileTransferObject = this.transfer.create(); this.takePicture().subscribe(data => { this.wait(7000);
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);});
}
我试图显示
base64文件,但它不起作用。要显示base64图像,需要在组件中导入DOMSanizer并在下面的构造函数中创建实例变量,代码如下
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)"/>
构造函数(public\u domsanizer:domsanizer)
我认为问题不在于显示图像。我已经尝试了画廊中的图片并正确显示。是否转换为base64文件不正确?我不确定。您是否在entry.toUrl()中获得了正确的图像url,并且是否检查了图像是否向下隐藏在本地文件中。还有一个问题,为什么要在this.room.img中传递两个值?图像是从entry.toUrl()显示的吗?