Merge pull request #1054 from Ali-RS/export-transparent-png

Modified JmeDesktopSystem.writeImageFile() to export transparency for…
accellbaker
Paul Speed 6 years ago committed by GitHub
commit 9a6032a087
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java

@ -90,19 +90,21 @@ public class JmeDesktopSystem extends JmeSystemDelegate {
@Override @Override
public void writeImageFile(OutputStream outStream, String format, ByteBuffer imageData, int width, int height) throws IOException { 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(); ImageWriter writer = ImageIO.getImageWritersByFormatName(format).next();
ImageWriteParam writeParam = writer.getDefaultWriteParam(); ImageWriteParam writeParam = writer.getDefaultWriteParam();
BufferedImage awtImage;
if (format.equals("jpg")) { if (format.equals("jpg")) {
JPEGImageWriteParam jpegParam = (JPEGImageWriteParam) writeParam; JPEGImageWriteParam jpegParam = (JPEGImageWriteParam) writeParam;
jpegParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); jpegParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
jpegParam.setCompressionQuality(0.95f); jpegParam.setCompressionQuality(0.95f);
} awtImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
Screenshots.convertScreenShot2(imageData.asIntBuffer(), awtImage);
awtImage = verticalFlip(awtImage); awtImage = verticalFlip(awtImage);
} else {
awtImage = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
Screenshots.convertScreenShot(imageData, awtImage);
}
ImageOutputStream imgOut = new MemoryCacheImageOutputStream(outStream); ImageOutputStream imgOut = new MemoryCacheImageOutputStream(outStream);
writer.setOutput(imgOut); writer.setOutput(imgOut);

Loading…
Cancel
Save