List of usage examples for java.awt.image IndexColorModel IndexColorModel
public IndexColorModel(int bits, int size, int[] cmap, int start, boolean hasalpha, int trans, int transferType)
From source file:ConvertUtil.java
/** * Converts the source image to 4-bit colour using the given colour map. No * transparency./* ww w . j a v a 2s . co m*/ * * @param src * the source image to convert * @param cmap * the colour map, which should contain no more than 16 entries * The entries are in the form RRGGBB (hex). * @return a copy of the source image with a 4-bit colour depth, with the * custom colour pallette */ public static BufferedImage convert4(BufferedImage src, int[] cmap) { IndexColorModel icm = new IndexColorModel(4, cmap.length, cmap, 0, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); BufferedImage dest = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_BINARY, icm); ColorConvertOp cco = new ColorConvertOp(src.getColorModel().getColorSpace(), dest.getColorModel().getColorSpace(), null); cco.filter(src, dest); return dest; }