Skip to content

Commit

Permalink
Merge pull request #1054 from Ali-RS/export-transparent-png
Browse files Browse the repository at this point in the history
Modified JmeDesktopSystem.writeImageFile() to export transparency for…
  • Loading branch information
pspeed42 committed Mar 22, 2019
2 parents 9f9b443 + c43eafc commit 9a6032a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java
Expand Up @@ -90,20 +90,22 @@ private static BufferedImage verticalFlip(BufferedImage original) {

@Override
public void writeImageFile(OutputStream outStream, String format, ByteBuffer imageData, int width, int height) throws IOException {
BufferedImage awtImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
Screenshots.convertScreenShot2(imageData.asIntBuffer(), awtImage);

ImageWriter writer = ImageIO.getImageWritersByFormatName(format).next();
ImageWriteParam writeParam = writer.getDefaultWriteParam();


BufferedImage awtImage;
if (format.equals("jpg")) {
JPEGImageWriteParam jpegParam = (JPEGImageWriteParam) writeParam;
jpegParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
jpegParam.setCompressionQuality(0.95f);
awtImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
Screenshots.convertScreenShot2(imageData.asIntBuffer(), awtImage);
awtImage = verticalFlip(awtImage);
} else {
awtImage = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
Screenshots.convertScreenShot(imageData, awtImage);
}

awtImage = verticalFlip(awtImage);

ImageOutputStream imgOut = new MemoryCacheImageOutputStream(outStream);
writer.setOutput(imgOut);
IIOImage outputImage = new IIOImage(awtImage, null, null);
Expand Down

0 comments on commit 9a6032a

Please sign in to comment.