Java BufferedImage Operation recolor(BufferedImage img, int newColor)

Here you can find the source of recolor(BufferedImage img, int newColor)

Description

Recolor a given default tile image.

License

LGPL

Parameter

Parameter Description
img the original image.
newColor the new RGBA color.

Return

the new RGBA image

Declaration

public static BufferedImage recolor(BufferedImage img, int newColor) 

Method Source Code


//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;
    }
}

Related

  1. outPutImage(BufferedImage bufferedimage, String targetPath)
  2. paletteSwapARGB8(Color[] colorSet, Color clearToColorRequested, BufferedImage argbMappedBufferedImage)
  3. palettize(BufferedImage img, int maxEntries)
  4. performRescaleOperation(BufferedImage image, float scale, float offset)
  5. prepareModel(BufferedImage model)
  6. recolor(BufferedImage src, Color sc)
  7. recombine(BufferedImage[][] blocks)
  8. reorientImage(BufferedImage image, boolean yAxisFlipNeeded, int cwRotationNeeded)
  9. repairImage(final BufferedImage bfi, final List order)