Nativescript imageSource.fromAsset getImageAsync 错误
Nativescript imageSource.fromAsset getImageAsync error
我正在尝试上传从设备图库中选取的 base64 编码图像。
基本上我select的图片设置为source
的一张ImageView
。
后来我上传 ImageView
的 src
是什么。
我使用 nativescript-imagepicker
作为图像的 selection :
let context = imagePicker.create({
mode : "single"
});
context.authorize()
.then(()=>{ return context.present();})
.then((selection)=>{
selection.forEach((selected)=>{
selected.getImage().then((value :ImageSource)=>{
imageView.src = value; //here I set the image as source
})
})
});
之后在上传方法中我尝试执行以下操作:
fromAsset
方法是 Nativescript 的 ImageSource
模块的一部分。
fromAsset(imageView.src).then(
(res) => {
imageSource = res;
photo.base64 = imageSource.toBase64String('jpg');
..
}).catch((error)=>{
console.log(error); // here I get TypeError.asset.getImageAsync is not a function
})
当我对直接从相机拍摄的图像使用上述方法时,一切顺利,但是 如果图像是 selected 来自画廊,我得到以下信息错误:TypeError.asset.getImageAsync 不是函数
我做错了什么?
我使用了这个 link 中的代码并且运行完美!希望有用https://github.com/NativeScript/nativescript-imagepicker/issues/62
我正在尝试上传从设备图库中选取的 base64 编码图像。
基本上我select的图片设置为source
的一张ImageView
。
后来我上传 ImageView
的 src
是什么。
我使用 nativescript-imagepicker
作为图像的 selection :
let context = imagePicker.create({
mode : "single"
});
context.authorize()
.then(()=>{ return context.present();})
.then((selection)=>{
selection.forEach((selected)=>{
selected.getImage().then((value :ImageSource)=>{
imageView.src = value; //here I set the image as source
})
})
});
之后在上传方法中我尝试执行以下操作:
fromAsset
方法是 Nativescript 的 ImageSource
模块的一部分。
fromAsset(imageView.src).then(
(res) => {
imageSource = res;
photo.base64 = imageSource.toBase64String('jpg');
..
}).catch((error)=>{
console.log(error); // here I get TypeError.asset.getImageAsync is not a function
})
当我对直接从相机拍摄的图像使用上述方法时,一切顺利,但是 如果图像是 selected 来自画廊,我得到以下信息错误:TypeError.asset.getImageAsync 不是函数
我做错了什么?
我使用了这个 link 中的代码并且运行完美!希望有用https://github.com/NativeScript/nativescript-imagepicker/issues/62