Here you can find the source of changeColor(BufferedImage image, Color color, Color replacement_color)
public static BufferedImage changeColor(BufferedImage image, Color color, Color replacement_color)
//package com.java2s; //License from project: Apache License import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; public class Main { public static BufferedImage changeColor(BufferedImage image, Color color, Color replacement_color) { BufferedImage dimg = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g = dimg.createGraphics(); g.setComposite(AlphaComposite.Src); g.drawImage(image, null, 0, 0);//w w w .ja v a 2 s . co m g.dispose(); for (int i = 0; i < dimg.getHeight(); i++) { for (int j = 0; j < dimg.getWidth(); j++) { if (dimg.getRGB(j, i) == color.getRGB()) { dimg.setRGB(j, i, replacement_color.getRGB()); } } } return dimg; } public static void drawImage(BufferedImage srcImg, BufferedImage img2Draw, int w, int h) { if (w == -1) w = (int) (srcImg.getWidth() / 2); if (h == -1) h = (int) (srcImg.getHeight() / 2); System.out.println("AWT Image Wt: " + w + " And Ht: " + h); Graphics2D g2 = srcImg.createGraphics(); g2.drawImage(img2Draw, w, h, null); g2.dispose(); } }