Java BufferedImage Operation recolor(BufferedImage src, Color sc)

Here you can find the source of recolor(BufferedImage src, Color sc)

Description

recolor

License

Open Source License

Declaration

public static BufferedImage recolor(BufferedImage src, Color sc) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.*;
import java.awt.image.*;

public class Main {
    public static BufferedImage recolor(BufferedImage src, Color sc) {
        float[][] colorMatrix = { { ((float) sc.getRed()) / 255f, 0, 0, 0 },
                { ((float) sc.getGreen()) / 255f, 0, 0, 0 }, { ((float) sc.getBlue()) / 255f, 0, 0, 0 },
                { 0f, 0f, 0f, 1f } };//  w  w w .  ja  v  a2s .co  m
        BandCombineOp changeColors = new BandCombineOp(colorMatrix, null);
        Raster sourceRaster = src.getRaster();
        WritableRaster displayRaster = sourceRaster.createCompatibleWritableRaster();
        changeColors.filter(sourceRaster, displayRaster);
        return new BufferedImage(src.getColorModel(), displayRaster, true, null);
    }
}

Related

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