我正在尝试在nativescript上使用MediaFilePicker,同时使用PhotoEditor插件来裁剪/编辑从相机拍摄的照片,但是我没有用...这是我的代码的一部分:>
let options: ImagePickerOptions = {
android: {
isCaptureMood: true, // if true then camera will open directly.
isNeedCamera: true,
maxNumberFiles: 1,
isNeedFolderList: true
}, ios: {
isCaptureMood: true, // if true then camera will open directly.
maxNumberFiles: 1
}
};
let mediafilepicker = new Mediafilepicker();
mediafilepicker.openImagePicker(options);
mediafilepicker.on("getFiles", function (res) {
let results = res.object.get('results');
let result = results[0];
let source = new imageSourceModule.ImageSource();
source.fromAsset(result.rawData).then((source) => {
const photoEditor = new PhotoEditor();
photoEditor.editPhoto({
imageSource: source,
hiddenControls: [],
}).then((newImage) => {
}).catch((e) => {
reject();
});
});
});
FilePicker的结果对象如下:
{
"type": "capturedImage",
"file": {},
"rawData": "[Circular]"
}
我相信如果图片是从相机拍摄的,请使用rawData字段,但是我不知道会出现哪种格式,以及如何将其提供给PhotoEditor插入进行播放。
有什么建议吗?
谢谢!
答案 0 :(得分:0)
问题出在这里的source.fromAsset(result.rawData)
这一行,result.rawData
不是ImageAsset
,而是PHAsset
。您将必须从ImageAsset
创建一个PHAsset
并将其传递给fromAsset
。这样看起来,
import { ImageAsset } from "tns-core-modules/image-asset";
....
....
imgSource.fromAsset(new ImageAsset(img)).then((source) => {
const photoEditor = new PhotoEditor();
console.log(source === imgSource);
photoEditor.editPhoto({
imageSource: source,
hiddenControls: [],
}).then((newImage: ImageSource) => {
console.log('Get files...');
// Here you can save newImage, send it to your backend or simply display it in your app
}).catch((e) => {
//reject();
});
});