我正在寻找使用svg-edit在浏览器中注释图像。图像上传到svg-edit嵌入的同一页面,需要在上传时动态设置,作为svg-edit的背景。可以这样做吗?
答案 0 :(得分:1)
你必须调用对象的方法,即svgCanvas.setBackground();
为此你可以创建一个扩展名,例如:ext-backchange.js
此文件看起来像这样:
svgEditor.addExtension("changeback", function() {
svgCanvas.setBackground('','abc.png');
return {};
});
然后在svg-edit.js中包含此扩展名,如同最后一行:
svgEditor.setConfig(
{
extensions: ['ext-backchange.js']
})
答案 1 :(得分:0)
您可以使用setImage Background(图像背景)功能
setImageBackground("image.png");
并在svg canvas.js中添加此函数setImageBackground此图像显示在画布上并可以旋转。
this.setImageBackground= function(val) {
var elem = addSvgElementFromJson({
"element": "image",
"attr": {
"x": ( svgcontent.getAttribute('x') - bgimg_with ) / 2,
"y": ( svgcontent.getAttribute('y') - bgimg_height ) / 2,
"width": bgimg_with,
"height": bgimg_height,
"id": 'ImgBckgd',
"opacity": 1,
"style": "pointer-events:inherit",
}
});
setHref(elem, last_good_img_url);
preventClickDefault(elem);
if(!elem) return;
var attrs = $(elem).attr(['width', 'height']);
var setsize = (!attrs.width || !attrs.height);
var cur_href = getHref(elem);
// Do nothing if no URL change or size change
if(cur_href !== val) {
setsize = true;
} else if(!setsize) return;
var batchCmd = new BatchCommand("Change Image URL");
setHref(elem, val);
batchCmd.addSubCommand(new ChangeElementCommand(elem, {
"#href": cur_href
}));
if(setsize) {
$(new Image()).load(function() {
var changes = $(elem).attr(['width', 'height']);
$(elem).attr({
width: this.width,
height: this.height
});
selectorManager.requestSelector(elem).resize();
batchCmd.addSubCommand(new ChangeElementCommand(elem, changes));
addCommandToHistory(batchCmd);
call("changed", [elem]);
}).attr('src',val);
} else {
addCommandToHistory(batchCmd);
}
};