Re: Sweet Home 3D JS Online

by kingoftailor » Fri Aug 12, 2022 5:25 pm

It's almost good. There is only a problem with the background color. It should be all white. (The invisible part is not white)

Code: Select all

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

                var planView = application.getHomeController(application.getHomes()[0]).getPlanController().getView();
                var oldGridColor = planView.gridColor;
                planView.gridColor = "white";
                planView.repaint();
                var canvas = document.createElement('canvas');
                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();
                    planView.gridColor = oldGridColor;
                    planView.repaint();
                }, 100);
            }
Image