~tapaal-contributor/tapaal/query-export-bug-1767615

« back to all changes in this revision

Viewing changes to src/pipe/gui/Export.java

merged in branch lp:~tapaal-contributor/tapaal/png-margins-fix-1762562 fixing PNG export and updated list of contributors

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
import java.awt.print.PageFormat;
11
11
import java.awt.print.PrinterException;
12
12
import java.awt.print.PrinterJob;
 
13
import java.awt.Rectangle;
13
14
import java.io.File;
14
15
import java.io.FileNotFoundException;
15
16
import java.io.FileOutputStream;
130
131
                f.close();
131
132
        }
132
133
 
133
 
        public static void toPNG(JComponent g, String filename) throws IOException {
 
134
        public static void toPNG(DrawingSurfaceImpl g, String filename) throws IOException {
134
135
                Iterator<ImageWriter> i = ImageIO.getImageWritersBySuffix("png");
135
136
                if (!i.hasNext()) {
136
137
                        throw new RuntimeException("No ImageIO exporters can handle PNG");
139
140
                File f = new File(filename);
140
141
                BufferedImage img = new BufferedImage(g.getPreferredSize().width, g.getPreferredSize().height, BufferedImage.TYPE_3BYTE_BGR);
141
142
                g.print(img.getGraphics());
142
 
                ImageIO.write(img, "png", f);
 
143
                Rectangle r = g.calculateBoundingRectangle();
 
144
                BufferedImage croppedImg = img.getSubimage(r.x, r.y, r.width, r.height);
 
145
                ImageIO.write(croppedImg, "png", f);
143
146
        }
144
147
 
145
148
        private static void toPrinter(DrawingSurfaceImpl g) throws PrintException {