6

我正在尝试加载具有图像对象的 json 对象。图像对象具有 base 64 图像数据作为背景。但我无法加载 loadFromJSON 方法。

代码:

var jsonDataSet = '{"objects":[{"type":"image","originX":"left","originY":"top","left":0,"top":0,"width":700,"height":600,"fill":"rgb(0,0,0)","overlayFill":null,"stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"selectable":false,"hasControls":true,"hasBorders":true,"hasRotatingPoint":true,"transparentCorners":true,"perPixelTargetFind":false,"shadow":null,"visible":true,"clipTo":null,"src":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAn4AAAFPCAYAAADTHsP1AAAgAElEQ…Lv/vuU1wVsyvXK+Kks1f6gffSCThZ1km3u6NFklCnFes//AbZzi+iGF3/7AAAAAElFTkSuQmCC","filters":[]}],"background":""}';

canvas.loadFromJSON (jsonDataSet);

canvas.renderAll();

它显示错误为"Error loading data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAn4AAAFPCAYAAADTHsP1AAAgAElEQ…Lv/vuU1wVsyvXK+Kks1f6gffSCThZ1km3u6NFklCnFes//AbZzi+iGF3/7AAAAAElFTkSuQmCC "

4

1 回答 1

4

如果您使用最新的 fabric.js 版本,这是一个错误。我已经通过拉取请求 #800 解决了这个问题:https ://github.com/kangax/fabric.js/pull/800 。

顺便说一句,您上面代码的 base64 dataURL 不正确 - 它有三个点(lEQ…Lv/vuU)。可能是复制的副作用。

于 2013-08-21T08:20:23.943 回答