summaryrefslogtreecommitdiff
path: root/src/net/sourceforge/plantuml/ugraphic/UImage.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/sourceforge/plantuml/ugraphic/UImage.java')
-rw-r--r--src/net/sourceforge/plantuml/ugraphic/UImage.java21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/net/sourceforge/plantuml/ugraphic/UImage.java b/src/net/sourceforge/plantuml/ugraphic/UImage.java
index 9834de0..2db8816 100644
--- a/src/net/sourceforge/plantuml/ugraphic/UImage.java
+++ b/src/net/sourceforge/plantuml/ugraphic/UImage.java
@@ -34,6 +34,8 @@
*/
package net.sourceforge.plantuml.ugraphic;
+import java.awt.geom.AffineTransform;
+import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
public class UImage implements UShape {
@@ -44,6 +46,25 @@ public class UImage implements UShape {
this.image = image;
}
+ public UImage(BufferedImage before, double scale) {
+ if (scale == 1) {
+ this.image = before;
+ return;
+ }
+
+ final int w = (int) Math.round(before.getWidth() * scale);
+ final int h = (int) Math.round(before.getHeight() * scale);
+ final BufferedImage after = new BufferedImage(w, h, before.getType());
+ final AffineTransform at = new AffineTransform();
+ at.scale(scale, scale);
+ final AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
+ this.image = scaleOp.filter(before, after);
+ }
+
+ public UImage scale(double scale) {
+ return new UImage(image, scale);
+ }
+
public final BufferedImage getImage() {
return image;
}