Re: Sweet Home 3D JS Online

by kingoftailor » Sat Aug 13, 2022 9:49 am

The problem was that a new canvas was created. This is how it works:

Code: Select all

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);
            }