diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2019-07-22 21:30:12 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2019-07-22 21:30:12 +0000 |
commit | e18eef07b19eb173867ba41dcd179b8dc2ca4e1d (patch) | |
tree | 4cce54d04d9cd719e4f1a7cadf006b30573b41c6 /src/java/org/apache/poi/sl/draw | |
parent | 58eb1a8070ea045deb0999f8d82f120f7a3c3bc6 (diff) | |
download | poi-e18eef07b19eb173867ba41dcd179b8dc2ca4e1d.tar.gz poi-e18eef07b19eb173867ba41dcd179b8dc2ca4e1d.zip |
Refactor alpha handling
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1863601 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/sl/draw')
-rw-r--r-- | src/java/org/apache/poi/sl/draw/BitmapImageRenderer.java | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/java/org/apache/poi/sl/draw/BitmapImageRenderer.java b/src/java/org/apache/poi/sl/draw/BitmapImageRenderer.java index 3643b976c0..e6a28a3c23 100644 --- a/src/java/org/apache/poi/sl/draw/BitmapImageRenderer.java +++ b/src/java/org/apache/poi/sl/draw/BitmapImageRenderer.java @@ -244,9 +244,9 @@ public class BitmapImageRenderer implements ImageRenderer { } double w_old = img.getWidth(); double h_old = img.getHeight(); - BufferedImage scaled = new BufferedImage((int)w_old, (int)h_old, BufferedImage.TYPE_INT_ARGB); double w_new = dim.getWidth(); double h_new = dim.getHeight(); + BufferedImage scaled = new BufferedImage((int)w_new, (int)h_new, BufferedImage.TYPE_INT_ARGB); AffineTransform at = new AffineTransform(); at.scale(w_new/w_old, h_new/h_old); AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR); @@ -263,16 +263,22 @@ public class BitmapImageRenderer implements ImageRenderer { @Override public void setAlpha(double alpha) { - if (img == null) return; + img = setAlpha(img, alpha); + } + + public static BufferedImage setAlpha(BufferedImage image, double alpha) { + if (image == null) { + return new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); + } - Dimension dim = getDimension(); - BufferedImage newImg = new BufferedImage((int)dim.getWidth(), (int)dim.getHeight(), BufferedImage.TYPE_INT_ARGB); - Graphics2D g = newImg.createGraphics(); - RescaleOp op = new RescaleOp(new float[]{1.0f, 1.0f, 1.0f, (float)alpha}, new float[]{0,0,0,0}, null); - g.drawImage(img, op, 0, 0); - g.dispose(); + if (alpha == 0) { + return image; + } - img = newImg; + float[] scalefactors = {1, 1, 1, (float)alpha}; + float[] offsets = {0,0,0,0}; + RescaleOp op = new RescaleOp(scalefactors, offsets, null); + return op.filter(image, null); } |