PhotoEditorSDK设置列表,贴纸作为其他图像的模板

时间:2018-04-16 12:45:56

标签: android photoeditorsdk

我使用Photo Editor SDK 5.0.20版,并希望使用带有贴纸的序列化设置列表作为其他图像的模板。

基本上,我加载了Photo Editor SDK Docs中描述的先前序列化的设置列表,其中只包含贴纸的操作:

{
    "version": "3.0.0",
    "meta": {
        "platform": "android",
        "version": "5.0.20",
        "createdAt": "2018-04-16T07:22:41+00:00"
    },
    "operations": [
        {
            "type": "sprite",
            "options": {
                "sprites": [
                    {
                        "type": "sticker",
                        "options": {
                            "identifier": "Wimpel",
                            "dimensions": {
                                "x": 1.0390830937992344,
                                "y": 0.3552596348364971
                            },
                            "position": {
                                "x": 0.093109130859375,
                                "y": 0.028560863807797432
                            },
                            "flipVertically": false,
                            "flipHorizontally": false,
                            "tintColor": {
                                "rgba": [
                                    0.0,
                                    0.0,
                                    0.0,
                                    0.0
                                ]
                            },
                            "rotation": 0.10879226105860895
                        }
                    },
                    {
                        "type": "sticker",
                        "options": {
                            "identifier": "Wimpel",
                            "dimensions": {
                                "x": 1.0693840954731448,
                                "y": 0.36561946347204366
                            },
                            "position": {
                                "x": 1.183990716934204,
                                "y": 0.2119801640510559
                            },
                            "flipVertically": false,
                            "flipHorizontally": false,
                            "tintColor": {
                                "rgba": [
                                    0.0,
                                    0.0,
                                    0.0,
                                    0.0
                                ]
                            },
                            "rotation": 0.06839104205767087
                        }
                    },
                    {
                        "type": "sticker",
                        "options": {
                            "identifier": "Tasse",
                            "dimensions": {
                                "x": 0.4046522174597027,
                                "y": 0.28636926158686654
                            },
                            "position": {
                                "x": 0.731689453125,
                                "y": 0.8851687908172607
                            },
                            "flipVertically": false,
                            "flipHorizontally": false,
                            "tintColor": {
                                "rgba": [
                                    0.0,
                                    0.0,
                                    0.0,
                                    0.0
                                ]
                            },
                            "rotation": 6.279117594930599
                        }
                    },
                    {
                        "type": "sticker",
                        "options": {
                            "identifier": "Mmmh",
                            "dimensions": {
                                "x": 0.27350121683039547,
                                "y": 0.25441973658641437
                            },
                            "position": {
                                "x": 0.604736328125,
                                "y": 0.7340571284294128
                            },
                            "flipVertically": false,
                            "flipHorizontally": false,
                            "tintColor": {
                                "rgba": [
                                    0.0,
                                    0.0,
                                    0.0,
                                    0.0
                                ]
                            },
                            "rotation": 6.225312686163292
                        }
                    },
                    {
                        "type": "sticker",
                        "options": {
                            "identifier": "Lachende Shira",
                            "dimensions": {
                                "x": 0.32523648876287115,
                                "y": 0.5730795920977503
                            },
                            "position": {
                                "x": 0.1793212890625,
                                "y": 0.8109974265098572
                            },
                            "flipVertically": false,
                            "flipHorizontally": false,
                            "tintColor": {
                                "rgba": [
                                    0.0,
                                    0.0,
                                    0.0,
                                    0.0
                                ]
                            },
                            "rotation": 0.007284810845802748
                        }
                    },
                    {
                        "type": "sticker",
                        "options": {
                            "identifier": "Busch",
                            "dimensions": {
                                "x": 0.38570687331007564,
                                "y": 0.2892801549825567
                            },
                            "position": {
                                "x": 0.157135009765625,
                                "y": 0.9686249494552612
                            },
                            "flipVertically": false,
                            "flipHorizontally": false,
                            "tintColor": {
                                "rgba": [
                                    0.0,
                                    0.0,
                                    0.0,
                                    0.0
                                ]
                            },
                            "rotation": 0.010578608482012749
                        }
                    }
                ]
            }
        }
    ]
}

这些贴纸应该显示在加载的图像上,但遗憾的是它不起作用。

我还尝试了其他序列化设置(例如过滤器),这些设置已正确应用于加载的图像。

序列化JSON中是否有错误或其他错误?

1 个答案:

答案 0 :(得分:0)

我发现在将序列化的JSON读入配置之前必须将我的自定义贴纸设置为配置,否则SDK无法找到序列化贴纸:

val settingsList = SettingsList().apply {
    ...
    val tools = arrayListOf<ToolConfigInterface>(...)
    val stickers = arrayListOf<StickerListConfigInterface>(...)
    config.setTools(tools).setStickerLists(stickers)

    val file = File(filesDir.path, "editor_template.json")
    if (file.exists()) {
        val reader = PESDKFileReader(this)
        try {
            reader.readJson(file)
            Timber.d("Read editor state json.")
        } catch (e: IOException) {
            Timber.e(e, "Could not read editor state json.")
        }
    }
}
PhotoEditorBuilder(this).setSettingsList(settingsList).startActivityForResult(this, PHOTO_EDITOR_REQUEST_CODE)