我试图在Fabric.js中显示以前保存的图形,然后将其转换为仅视图,无编辑模式。这就是我所拥有的:
canvas1.loadFromJSON(cavasData, canvas1.renderAll.bind(canvas1));
canvas1.isDrawingMode = false;
canvas1.deactivateAll();
canvas1.selection = false;
但它并不是不可触碰的。显示正常,但对象仍然可以选择并且可以更改。
答案 0 :(得分:7)
从json
加载时,您应该禁用对象选择,
canvas.loadFromJSON(json, canvas.renderAll.bind(canvas), function(o, object) {
object.set('selectable', false);
});
<强> FIDDLE 强>
答案 1 :(得分:0)
最简单和最稳定的方法是在父 HTML 元素上设置 def my_collate(batch):
len_batch = len(batch)
batch = list(filter(lambda x: x is not None, batch))
if len_batch > len(batch):
db_len = len(dataset)
diff = len_batch - len(batch)
while diff != 0:
a = dataset[np.random.randint(0, db_len)]
if a is None:
continue
batch.append(a)
diff -= 1
return torch.utils.data.dataloader.default_collate(batch)
css 属性:
pointer-events
要从 javascript 设置此属性:
.locked {
pointer-events: none;
}
解锁画布:
let canvasElement = document.getElementsByClassName("canvas-container")[0]
canvasElement.classList.add("locked")