public class Picture extends AbstractFile {
+ private static void ensureNonzeroImageArea(final java.awt.Dimension result) {
+ if (result.width < 1)
+ result.width = 1;
+ if (result.height < 1)
+ result.height = 1;
+ }
+
/**
* Actual returned target thumbnail size will be adjusted from desired one
* by attempting to generate as large as possible thumbnail, while not
desiredTargetDimension.width,
(int) (desiredTargetDimension.width / inputImageWidthToHeightRatio));
+ ensureNonzeroImageArea(result);
+
return result;
} else {
(int) (desiredTargetDimension.height * inputImageWidthToHeightRatio),
desiredTargetDimension.height);
+ ensureNonzeroImageArea(result);
+
return result;
}
}
public static Image scaleImage(final Image srcImage, final int width,
final int height) {
- ImageFilter filter;
- filter = new java.awt.image.AreaAveragingScaleFilter(width, height);
+ final ImageFilter filter = new java.awt.image.AreaAveragingScaleFilter(
+ width, height);
final ImageProducer prod = new FilteredImageSource(
srcImage.getSource(), filter);
final Image newImage = Toolkit.getDefaultToolkit().createImage(prod);
- final ImageIcon imageIcon = new ImageIcon(newImage);
- return imageIcon.getImage();
+ return new ImageIcon(newImage).getImage();
}
private static final long serialVersionUID = -4156533490858298387L;;