我正在开展一个学校项目,我遇到了障碍。在此项目中,我们不允许使用任何外部库。我们有一个Canvas元素,用作ER图表建模的工作空间。我们必须使用Canvas元素。现在我们要将canvas-element中的所有内容导出为.SVG图片。我已经使用了.JPG图片。但有没有办法在.Javascript中将.JPG图片转换为.SVG图片?
以下是将画布导出为.JPG图片的代码。
$(document).ready(function(){
function downloadCanvas(link, canvasId, filename) {
link.href = document.getElementById(canvasId).toDataURL();
link.download = filename;
}
//picid is the id of the button that is used to export the picture.
//it doesn't work to just add .svg in the filename.
document.getElementById('picid').addEventListener('click', function(){
downloadCanvas(this, 'myCanvas', 'picture.jpg');
}, false);
});
.JPG图片采用BASE64代码。