Here you can find the source of findLegacyColorModel(BufferedImage image)
public static ColorModel findLegacyColorModel(BufferedImage image)
//package com.java2s; import java.awt.Transparency; import java.awt.color.ColorSpace; import java.awt.image.BufferedImage; import java.awt.image.ColorModel; import java.awt.image.ComponentColorModel; import java.awt.image.DataBuffer; public class Main { public final static ColorModel COLOR_MODEL_RGBA = new ComponentColorModel( ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] { 8, 8, 8, 8 }, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE); public final static ColorModel COLOR_MODEL_RGB = new ComponentColorModel( ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] { 8, 8, 8, 0 }, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); public final static ColorModel COLOR_MODEL_GRAY = new ComponentColorModel( ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] { 8 }, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); public final static ColorModel COLOR_MODEL_ALPHA = new ComponentColorModel( ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] { 0, 0, 0, 8 }, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE); public static ColorModel findLegacyColorModel(boolean inColor, boolean hasAlpha) { ColorModel colorModel = null; return colorModel; }//from www . j a v a 2s. c o m public static ColorModel findLegacyColorModel(BufferedImage image) { ColorModel sourceColorModel = image.getColorModel(); boolean inColor = (sourceColorModel.getColorSpace().getType() != ColorSpace.TYPE_GRAY); boolean hasAlpha = sourceColorModel.hasAlpha(); if (inColor) { if (hasAlpha) { return COLOR_MODEL_RGBA; } else { return COLOR_MODEL_RGB; } } else { if (hasAlpha) { return COLOR_MODEL_ALPHA; } else { return COLOR_MODEL_GRAY; } } } }