Fixed issues with transparent images master
authorbilde2910 <marius@varden.info>
Wed, 30 Jul 2014 22:00:15 +0000 (00:00 +0200)
committerbilde2910 <marius@varden.info>
Wed, 30 Jul 2014 22:00:15 +0000 (00:00 +0200)
src/main/java/info/varden/imagetint/ImageTint.java

index e04ddbc..665fc66 100644 (file)
@@ -1,7 +1,6 @@
 package info.varden.imagetint;
 
 import java.awt.AlphaComposite;
-import java.awt.Color;
 import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.image.BufferedImage;
@@ -55,16 +54,22 @@ public class ImageTint {
                                Graphics g = result.getGraphics();
                                g.drawImage(inputImg, 0, 0, null);
                                
+                               BufferedImage temp = new BufferedImage(w2, h2, BufferedImage.TYPE_INT_ARGB);
+                               for (int x = 0; x < w2; x++) {
+                                       for (int y = 0; y < h2; y++) {
+                                               temp.setRGB(x, y, (inputImg.getRGB(x, y) & 0xFF000000) + (int) (col & 0xFFFFFF));
+                                       }
+                               }
+                               
                                BufferedImage wm = new BufferedImage(w2, h2, BufferedImage.TYPE_INT_ARGB);
                                Graphics2D wmg = (Graphics2D) wm.getGraphics();
                                wmg.setComposite(AlphaComposite.SrcOver.derive(alpha));
-                               Color c = new Color((int) (col & 0xFFFFFF));
-                               wmg.setPaint(c);
-                               wmg.fillRect(0, 0, w2, h2);
+                               wmg.drawImage(temp, 0, 0, null);
                                wmg.dispose();
                                g.drawImage(wm, 0, 0, null);
                                g.dispose();
                                wm.flush();
+                               temp.flush();
                                String name = f.getName();
                                int pos = name.lastIndexOf(".");
                                if (pos > 0) {