Comment multiplier par un alpha (entre 0 et 1) le ARGB d'une image (ici issue d'un ImageIcon, et mémoriser le résultat dans une BufferedImage.
public class BrighterImage extends BufferedImage { private float alpha; Graphics2D g; public BrighterImage(ImageIcon imageIcon, float alpha) { super(imageIcon.getIconWidth(), imageIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB | transparency.TRANSLUCENT); this.alpha = alpha; this.g = this.createGraphics(); this.getGraphics().setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, this.alpha)); imageIcon.paintIcon(null, this.getGraphics(), 0, 0); } public Graphics2D getGraphics() { return this.g; } }
Bien sûr, la façon d'appliquer le facteur alpha peut varier, le champ « SRC_OVER » n'obligeant ici qu'à utiliser un algorithme précis.