Here you can find the source of recolor(BufferedImage img, int newColor)
Parameter | Description |
---|---|
img | the original image. |
newColor | the new RGBA color. |
public static BufferedImage recolor(BufferedImage img, int newColor)
//package com.java2s; /*/*from w w w .j a va 2 s. c om*/ * Copyright 2008-2014, David Karnok * The file is part of the Open Imperium Galactica project. * * The code should be distributed under the LGPL license. * See http://www.gnu.org/licenses/lgpl.html for details. */ import java.awt.image.BufferedImage; public class Main { /** * Recolor a given default tile image. * @param img the original image. * @param newColor the new RGBA color. * @return the new RGBA image */ public static BufferedImage recolor(BufferedImage img, int newColor) { int[] pixels = new int[img.getWidth() * img.getHeight()]; img.getRGB(0, 0, img.getWidth(), img.getHeight(), pixels, 0, img.getWidth()); for (int i = 0; i < pixels.length; i++) { int c = pixels[i]; if (c == 0xFF000000) { pixels[i] = newColor; } } BufferedImage result = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB); result.setRGB(0, 0, img.getWidth(), img.getHeight(), pixels, 0, img.getWidth()); return result; } }