【问题标题】:Nativescript- imagecropper return an empty objectNativescript- imagecropper 返回一个空对象
【发布时间】:2020-06-14 09:12:54
【问题描述】:

我需要裁剪我的图像。如果我只是保存图像 ti 服务器没关系,但如果我使用 imagecropper 我没有任何图像源。 ImageCropper 返回args.image = {android: {}}。 我使用 nativescript-imagecropper 插件。

这是我的裁剪方法:

 public onTakePicture(): void {
            const options = { lockSquare: true };
            const androidOptions = <OptionsAndroid>{
                isFreeStyleCropEnabled: true,
                statusBarColor: 'black',
                setAspectRatioOptions: {
                    defaultIndex: 0,
                    aspectRatios: [
                        {
                            aspectRatioTitle: '1:1',
                            aspectRatioX: 1,
                            aspectRatioY: 1
                        },
                        {
                            aspectRatioTitle: '16:9',
                            aspectRatioX: 16,
                            aspectRatioY: 9
                        },
                        {
                            aspectRatioTitle: '18:9',
                            aspectRatioX: 18,
                            aspectRatioY: 9
                        }
                    ]
                }
            };
            requestPermissions().then(() => {
                takePicture({ width: 300, height: 300, keepAspectRatio: true }).then((image) => {
                    ImageSource.fromAsset(image).then((source) => {
                        setTimeout(
                            () => {
                                this.imageCropper
                                    .show(source, options, androidOptions)
                                    .then((args) => {
                                        if (args.image !== null) {
                                            this.imageUrl = args.image;
                                        }
                                    })
                                    .catch(function (e) {
                                        console.dir(e);
                                    });
                            },
                            isAndroid ? 0 : 1000
                        );
                    });
                });
            });
        }

【问题讨论】:

    标签: angular nativescript tns


    【解决方案1】:

    尝试使用:console.log('images is '+args.image.android) 记录它 你应该得到类似的东西:图像是android.graphics.Bitmap@34ea206

    【讨论】:

      【解决方案2】:

      args.image 虽然看起来不是空的,但不知道为什么。你可以试试这个

                        import * as fsModule from "tns-core-modules/file-system";
      
      
      
                              let folder = fsModule.knownFolders.documents();
                              let filename =
                                "image-" + new Date().getTime() + ".jpg";
                              let path = fsModule.path.join(
                                folder.path,
                                filename
                              );
                              args.image.saveToFile(path, "jpeg");
                              args.image.filename = filename;
                              args.image.path = path;
      

      您现在可以访问 args.image 的这些属性;

      【讨论】:

        猜你喜欢
        • 2021-03-31
        • 2014-07-15
        • 2018-08-25
        • 2020-10-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多