2013-08-21 36 views
6

我想加載一個具有圖像對象的json對象。圖像對象具有基礎64圖像數據作爲背景。但我無法支持loadFromJSON方法。base64圖像數據不能與loadJSON in fabricjs

代碼:

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

顯示錯誤如果您使用最新版本fabric.js這是一個錯誤。我已經通過拉動請求#800修復了這個問題:https://github.com/kangax/fabric.js/pull/800

順便說一下,你上面代碼的base64 dataURL是不正確的 - 它有三個點(lEQ ... lv/vuU)。 可能是複製的副作用。

+1

非常感謝。添加了您的更改並且按預期工作。 – user2571818

+0

這三個點不是複製的副作用,它們實際上是由fabric.js添加的。查看控制檯中的輸出:http://jsfiddle.net/h9q6Lorg/ – BruceHill

+2

它們不是由fabric.js添加的。這是Chrome開發工具中的console.log的bug /限制(https://code.google.com/p/chromium/issues/detail?id=464560)。 http://jsfiddle.net/devxyrro/ – Kienz