如何使用nativescript imagepicker设置图像的方向

时间:2016-11-15 12:30:44

标签: android plugins nativescript

使用nativescript-imagepicker插件选择图像。有时图像方向是不正确的事件,尽管它在拾取器中是正确的。我怀疑它与拍摄照片的方向有关,但它非常不一致。

public pick(){
        var context = imagePicker.create({
            mode: 'single'
        });

        if (platformModule.device.os === "Android" && platformModule.device.sdkVersion >= 23)  {   
            permissions.requestPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE, "I need these permissions to read from storage")
            .then(function() {
                console.log("Permissions granted!");
                startSelection(context);
            })
            .catch(function() {
                console.log("Uh oh, no permissions - plan B time!");
            });
            } else {
                startSelection(context);
            }   

        }

export function startSelection(context){
    context.authorize()
            .then(
                () => {
                    return context.present();
                }
            )
            .then(
                (selection) => {
                    selection.forEach(function(selected){
                        selected.getImage()
                            .then((imageSource) => {
                                        var appPath = filesystem.knownFolders.currentApp().path;
                                        var profilePath = "/images/profile.png";
                                        var filePath = filesystem.path.join(appPath, profilePath);
                                        var saved = imageSource.saveToFile(filePath, enums.ImageFormat.jpg);
                                        console.log(`item saved:${saved}`);
                                        console.log("FilePath: " + filePath);
                                        console.log("Image source " + JSON.stringify(imageSource));
                                        navigationModule.gotoMainPage();
                                    },
                                    (error) => {
                                    console.log("error");
                                })
                })
    })
}

Image Picker

Result 1

Result 2

0 个答案:

没有答案