Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

Fixed JPEG snapshot resizing when running on OpenJDK.

luccioman1de86cf1bf35
diff --git a/htroot/api/snapshot.java b/htroot/api/snapshot.java
index db60af1b7..c79c1eb97 100644
--- a/htroot/api/snapshot.java
+++ b/htroot/api/snapshot.java
@@ -21,6 +21,7 @@
import java.awt.Container;
import java.awt.Image;
import java.awt.MediaTracker;
+import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
@@ -312,7 +313,14 @@ public class snapshot {
final MediaTracker mediaTracker = new MediaTracker(new Container());
mediaTracker.addImage(scaled, 0);
try {mediaTracker.waitForID(0);} catch (final InterruptedException e) {}
- return new EncodedImage(scaled, ext, true);
+
+ /*
+ * Ensure there is no alpha component on the ouput image, as it is pointless
+ * here and it is not well supported by the JPEGImageWriter from OpenJDK
+ */
+ BufferedImage scaledBufferedImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
+ scaledBufferedImg.createGraphics().drawImage(scaled, 0, 0, width, height, null);
+ return new EncodedImage(scaledBufferedImg, ext, true);
} catch (IOException e) {
ConcurrentLog.logException(e);
return null;
diff --git a/source/net/yacy/peers/graphics/EncodedImage.java b/source/net/yacy/peers/graphics/EncodedImage.java
index 7e08c61be..c54e96379 100644
--- a/source/net/yacy/peers/graphics/EncodedImage.java
+++ b/source/net/yacy/peers/graphics/EncodedImage.java
@@ -20,7 +20,6 @@
package net.yacy.peers.graphics;
-import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.ColorConvertOp;
import java.io.ByteArrayOutputStream;
@@ -90,30 +89,6 @@ public class EncodedImage {
}
- /**
- * set an encoded image from a buffered image. Image ByteBuffer will be empty when encoding format is not supported.
- * @param sourceImage the image
- * @param targetExt the target extension of the image when converted into a file
- * @param isStatic shall be true if the image will never change, false if not
- */
- public EncodedImage(final Image i, final String targetExt, final boolean isStatic) {
- this.extension = targetExt;
- this.isStatic = isStatic;
-
- // generate an byte array from the generated image
- int width = i.getWidth(null);
- if (width < 0) {
- width = 96; // bad hack
- }
- int height = i.getHeight(null);
- if (height < 0) {
- height = 96; // bad hack
- }
- final BufferedImage sourceImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- sourceImage.createGraphics().drawImage(i, 0, 0, width, height, null);
- this.image = RasterPlotter.exportImage(sourceImage, targetExt);
- }
-
/**
* set an encoded image from an animated GIF. The target extension will be "gif"
* @param sourceImage the image