From 2b5a8021973ab2321d3b20df7a33b9a9aacdb2f4 Mon Sep 17 00:00:00 2001 From: Benjamin Maus Date: Sun, 26 May 2013 14:19:29 +0200 Subject: [PATCH] Fixes processing/processing#1810 where a png data would be written instead of jpeg data. --- core/src/processing/core/PImage.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/core/src/processing/core/PImage.java b/core/src/processing/core/PImage.java index 5887c9d55..d1747b173 100644 --- a/core/src/processing/core/PImage.java +++ b/core/src/processing/core/PImage.java @@ -3109,6 +3109,7 @@ public class PImage implements PConstants, Cloneable { ImageWriter writer = null; ImageWriteParam param = null; IIOMetadata metadata = null; + if (extension.equals("jpg") || extension.equals("jpeg")) { if ((writer = imageioWriter("jpeg")) != null) { // Set JPEG quality to 90% with baseline optimization. Setting this @@ -3120,12 +3121,16 @@ public class PImage implements PConstants, Cloneable { param.setCompressionQuality(0.9f); } } - if ((writer = imageioWriter("png")) != null) { - param = writer.getDefaultWriteParam(); - if (false) { - metadata = imageioDPI(writer, param, 100); + + if (extension.equals("png")) { + if ((writer = imageioWriter("png")) != null) { + param = writer.getDefaultWriteParam(); + if (false) { + metadata = imageioDPI(writer, param, 100); + } } } + if (writer != null) { BufferedOutputStream output = new BufferedOutputStream(PApplet.createOutput(file));