2
我的猜測是,這是我做錯了什麼....從JSON加載 - 對象未縮放?
使用toJSON和fromJSON方法保存和加載結構圖,似乎縮放對象不保留其縮放比例。
僅供參考,PNG文件它創建看的權利。
所以,這裏的圖像是什麼樣子,當我將它保存:
然後,當我重新加載它:
代碼:
function save() {
// Need to clear selection and remove overlay before saving.
canvas.deactivateAll();
if (!mask) {canvas.setOverlayImage('', canvas.renderAll.bind(canvas));}
// If they're zoomed in, reset the image
resetZoom();
var name = prompt("Please enter a filename", "NewPresentation");
var url = 'http://localhost/fabric/img/'+name+'.png';
var stat = checkUrl(url);
//console.log("Stat: "+stat);
if (stat) {
if (!confirm(url+" already exists. Do you want to overwrite the existing file?")) return false;
}
$.ajax({
type: 'POST',
url: 'save.php',
data: {
task: 'save',
img: canvas.toDataURL('png'),
json: JSON.stringify(canvas.toJSON()),
name: name,
coid: companyId,
id: ''
},
success: function(json) {
if (!json.success) {
alert('Error!'); return;
currPresId = json.id;
}
}
});
if (!mask) {canvas.setOverlayImage('dist/pixelmask.png', canvas.renderAll.bind(canvas));}
list();
}
加載程序:
function loadPresentation(id) {
console.log("We should be loading "+id);
$.ajax({
type: 'GET',
url: 'loadPresentation.php',
data: {
id: id
},
success: function(json) {
console.log("Success");
var j = JSON.parse(json);
canvas.loadFromJSON(j);
}
});
}
任何人都可以指出我可能會做什麼,會導致這種情況?在此先感謝您的幫助。如果我沒有給你一些你需要排除故障的事情,LMK,我很快就會在這裏得到它。
你剛纔救了我的工作一噸,謝謝! – Snouto
感謝您發佈這個!不能相信這不是更爲人所熟知。這個問題在我的編輯器中確實造成了問題。 – BWDesign