1.1 --- a/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/SingleImageResizer.java Mon Nov 17 01:17:02 2014 +0100
1.2 +++ b/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/SingleImageResizer.java Mon Nov 17 17:02:48 2014 +0100
1.3 @@ -20,8 +20,9 @@
1.4 import java.awt.Graphics2D;
1.5 import java.awt.image.BufferedImage;
1.6 import java.io.IOException;
1.7 -import java.io.InputStream;
1.8 import java.io.OutputStream;
1.9 +import java.util.logging.Level;
1.10 +import java.util.logging.Logger;
1.11 import java.util.regex.Pattern;
1.12 import javax.imageio.ImageIO;
1.13
1.14 @@ -31,10 +32,11 @@
1.15 */
1.16 public class SingleImageResizer {
1.17
1.18 - public void resize(InputStream input, OutputStream output, ImageFormat outputFormat) throws ResizeException {
1.19 + private static final Logger log = Logger.getLogger(SingleImageResizer.class.getName());
1.20 +
1.21 + public void resize(BufferedImage input, OutputStream output, SizeSpecification size, ImageFormat outputFormat) throws ResizeException {
1.22 try {
1.23 - BufferedImage image = ImageIO.read(input);
1.24 - BufferedImage resized = resize(image, 64, 64, image.getType());
1.25 + BufferedImage resized = resize(input, size.getWidth(), size.getHeight(), input.getType());
1.26
1.27 ImageIO.write(resized, outputFormat.getFormat(), output);
1.28 } catch (IOException e) {
1.29 @@ -56,6 +58,11 @@
1.30 height = maxHeight;
1.31 }
1.32
1.33 + if (type == BufferedImage.TYPE_CUSTOM) {
1.34 + log.log(Level.FINE, "Setting default image type: from TYPE_CUSTOM to TYPE_INT_ARGB");
1.35 + type = BufferedImage.TYPE_INT_ARGB;
1.36 + }
1.37 +
1.38 BufferedImage resized = new BufferedImage(width, height, type);
1.39 Graphics2D g = resized.createGraphics();
1.40 g.drawImage(original, 0, 0, width, height, null);
1.41 @@ -78,6 +85,9 @@
1.42 this.regex = regex;
1.43 }
1.44
1.45 + /**
1.46 + * @return format name for {@linkplain ImageIO#write(java.awt.image.RenderedImage, java.lang.String, java.io.File)
1.47 + */
1.48 public String getFormat() {
1.49 return format;
1.50 }