Skip to content

Commit

Permalink
Moved the file writing in screen shot app state to its own
Browse files Browse the repository at this point in the history
method... 1) because it's a little cleaner, 2) because it means
subclasses can hook it if desired.
  • Loading branch information
pspeed42 committed Mar 13, 2016
1 parent f391b9c commit 0b487ee
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions jme3-core/src/main/java/com/jme3/app/state/ScreenshotAppState.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,21 +249,23 @@ public void postFrame(FrameBuffer out) {
}
logger.log(Level.FINE, "Saving ScreenShot to: {0}", file.getAbsolutePath());

OutputStream outStream = null;
try {
outStream = new FileOutputStream(file);
JmeSystem.writeImageFile(outStream, "png", outBuf, width, height);
writeImageFile(file);
} catch (IOException ex) {
logger.log(Level.SEVERE, "Error while saving screenshot", ex);
} finally {
if (outStream != null){
try {
outStream.close();
} catch (IOException ex) {
logger.log(Level.SEVERE, "Error while saving screenshot", ex);
}
}
}
}
}
}

/**
* Called by postFrame() once the screen has been captured to outBuf.
*/
protected void writeImageFile( File file ) throws IOException {
OutputStream outStream = new FileOutputStream(file);
try {
JmeSystem.writeImageFile(outStream, "png", outBuf, width, height);
} finally {
outStream.close();
}
}
}

0 comments on commit 0b487ee

Please sign in to comment.