0
ユーザーのギャラリーから画像を選択しようとしています。画像をImageView
で表示し、アップロードして保存します。NativeScript imagepickerで選択したファイルを保存する方法
私はnativescript-imagepicker
プラグインを使用しています。ここで
は私がギャラリーから画像を選択し、ImageView
でそれを設定する方法である:
export function selectPicture() :void{
let context = imagePicker.create({
mode : "single"
});
context.authorize()
.then(()=>{ return context.present();})
.then((selection)=>{
selection.forEach((selected)=>{
selected.getImage().then((value :ImageSource)=>{
imageView.imageSource = value;
})
})
});
}
アンこれは、私はそれを保存し、それをアップロードする方法です:
export function upload():void{
try {
let photoPath = FileNameService.generatePictureFilePath();
let fileName = FileNameService.getFilenameFromPath(photoPath);
//this is where I get the error
**fromAsset(imageView.src)**.then(
(res) => {
imageSource = res;
let saved = imageSource.saveToFile(...);
if(saved){//doStuff },
(error)=>{
alert("Error " + error);
})
}catch (e){
alert(e);
}
}
fromAsset機能が投げています次のエラー:
asset.getImageAsync is not a function
私は間違って何をしていますか?
Nikolayの答えは正しい以上ですが、 "imagesource.saveToFile(path、enums.ImageFormat.png);"のようなenumsモジュールを使ってファイル形式を追加します。ちょうどあなたがIOSまたはAndroidの互換性に関する驚きを持っていないことを確認するために – Kansen
ありがとう! jpgはiosでサポートされていませんか? –