Print at Dec 18, 2025, 3:50:44 AM

Posted by kingoftailor at Aug 13, 2022, 9:49:32 AM
Re: Sweet Home 3D JS Online
The problem was that a new canvas was created. This is how it works:


function AlaprajzMentes() {
let downloadLink = document.createElement('a');
downloadLink.setAttribute('download', 'alaprajz.jpg');

let canvas = document.getElementById('home-plan.canvas');
var planView = application.getHomeController(application.getHomes()[0]).getPlanController().getView();
planView.gridColor = "white";
planView.repaint();
canvas.width = planView.getPreferredSize().width * 2;
canvas.height = planView.getPreferredSize().height * 2;
planView.paintComponent(new Graphics2D(canvas));

setTimeout(function () {
let dataURL = canvas.toDataURL('image/jpg');
let url = dataURL.replace(/^data:image\/jpg/, 'data:application/octet-stream');
downloadLink.setAttribute('href', url);
downloadLink.click();
window.location.reload();
}, 100);
}