从过滤器FabricJS导出自定义数据

时间:2016-06-01 09:35:56

标签: javascript canvas html5-canvas fabricjs

¿我可以使用方法toDatalessJSON导出个性化过滤器属性吗?

我有这个canvas对象,当我使用toDatalessJSON进行序列化时,属性不是序列化。

{
        "type": "image",
        "height": 647,
        "fill": "rgb(0,0,0)",
        "stroke": null,
        "strokeWidth": 0,
        "strokeDashArray": null,
        "strokeLineCap": "butt",
        "strokeLineJoin": "miter",
        "strokeMiterLimit": 10,
        "scaleX": 0.23,
        "scaleY": 0.23,
        "angle": 0,
        "flipX": false,
        "flipY": false,
        "opacity": 1,
        "shadow": null,
        "visible": true,
        "clipTo": null,
        "backgroundColor": "",
        "fillRule": "nonzero",
        "globalCompositeOperation": "source-over",
        "transformMatrix": null,
        "skewX": 0,
        "skewY": 0,
        "lockUniScaling": false,
        "borderColor": "rgba(102,153,255,0.75)",
        "cornerColor": "rgba(102,153,255,0.5)",
        "cornerSize": 13,
        "lockMovementX": false,
        "lockMovementY": false,
        "lockScalingX": false,
        "lockScalingY": false,
        "lockScalingFlip": false,
        "lockRotation": false,
        "transparentCorners": true,
        "padding": 0,
        "hasBorders": true,
        "hasControls": true,
        "nombre": "Objeto_7",
        "tipo": "",
        "src": "cuadradito.png",
        "filters": [
            {
                "color": "#000000",
                "image": false,
                "mode": "multiply",
                "alpha": 1,
                "submode": "add"
            }
        ],
        "resizeFilters": [],
        "crossOrigin": "",
        "alignX": "none",
        "alignY": "none",
        "meetOrSlice": "meet"
    }
],
"background": "#ffffff"

}

当我序列化画布时,我想导出属性子模式。我怎么能这样做?

感谢您阅读。

1 个答案:

答案 0 :(得分:0)

Hello尝试覆盖'toObject'函数,如

 obj.toObject = (function (toObject) {
        return function () {
            return fabric.util.object.extend(toObject.call(this), {
               //here add the properties that you want to export to json object

                filters: this.filters//this will export all the filters object
            });
        };
    })(obj.toObject);

然后您可以导出对象并查看自定义属性。

希望有助于好运。