Base64图像数据不与fabricjs中的loadfromJSON一起使用

时间:2013-08-21 06:31:41

标签: javascript canvas base64 fabricjs

我正在尝试加载一个有图像对象的json对象。图像对象具有基础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 "

1 个答案:

答案 0 :(得分:4)

如果你使用最新的fabric.js版本,那就是一个bug。我已经通过拉取请求#800修复了这个问题:https://github.com/kangax/fabric.js/pull/800

BTW你的base64 dataURL上面的代码不正确 - 它有三个点(lEQ ... Lv / vuU)。 可能是复制的副作用。