gann-cdf /
turtle-logo
| 1 | package org.gannacademy.cdf.turtlelogo.docs; |
||
| 2 | |||
| 3 | import org.gannacademy.cdf.turtlelogo.Terrarium; |
||
| 4 | |||
| 5 | import javax.imageio.ImageIO; |
||
| 6 | import java.awt.*; |
||
| 7 | import java.awt.image.BufferedImage; |
||
| 8 | import java.io.File; |
||
| 9 | import java.io.IOException; |
||
| 10 | |||
| 11 | public class SavableTerrarium extends Terrarium { |
||
| 12 | public void drawTo(String path) { |
||
| 13 | drawTo(path, "PNG"); |
||
| 14 | } |
||
| 15 | |||
| 16 | public void drawTo(String path, String format) { |
||
| 17 | try { |
||
| 18 | BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); |
||
| 19 | Graphics2D context = image.createGraphics(); |
||
| 20 | context.setPaint(getBackground()); |
||
| 21 | context.fillRect(0, 0, image.getWidth(), image.getHeight()); |
||
| 22 | draw(context); |
||
| 23 | ImageIO.write(image, format, new File(path)); |
||
| 24 | } catch (IOException e) { |
||
| 25 | e.printStackTrace(); |
||
|
0 ignored issues
–
show
Best Practice
introduced
by
Loading history...
|
|||
| 26 | } |
||
| 27 | } |
||
| 28 | } |
||
| 29 |