Here you can find the source of tintImage(BufferedImage src, Color color, float tintOpacity)
public static BufferedImage tintImage(BufferedImage src, Color color, float tintOpacity)
//package com.java2s; //License from project: Open Source License import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.awt.image.Raster; public class Main { public static BufferedImage tintImage(BufferedImage src, Color color, float tintOpacity) { BufferedImage img = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TRANSLUCENT); Graphics2D g2d = img.createGraphics(); //Draw the base image g2d.drawImage(src, null, 0, 0);/*from www . ja v a2s .com*/ //Set the color to a transparent version of the input color g2d.setColor( new Color(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, tintOpacity)); //Iterate over every pixel, if it isn't transparent paint over it Raster data = src.getData(); for (int x = data.getMinX(); x < data.getWidth(); x++) { for (int y = data.getMinY(); y < data.getHeight(); y++) { int[] pixel = data.getPixel(x, y, new int[4]); if (pixel[0] == 0 && pixel[1] == 0 && pixel[2] == 0) { continue; } if (pixel[3] > 0) { //If pixel isn't full alpha. Could also be pixel[3]==255 g2d.fillRect(x, y, 1, 1); } } } g2d.dispose(); return img; } }