Here you can find the source of depalettize(BufferedImage img, int maxBytes)
public static BufferedImage depalettize(BufferedImage img, int maxBytes)
//package com.java2s; /*/*from w ww. j a v a 2 s . c o m*/ * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ import java.awt.image.BufferedImage; import java.awt.image.ColorModel; import java.awt.image.IndexColorModel; public class Main { /** * Convert an image to a direct color map */ public static BufferedImage depalettize(BufferedImage img, int maxBytes) { // Even is we use an RGB buffer instead of RGBA it still uses 4 bytes in memory if (img.getWidth() * img.getHeight() * 4 > maxBytes) { // Image is too large to depalettize return null; } ColorModel colorModel = img.getColorModel(); if (colorModel instanceof IndexColorModel) { IndexColorModel indexModel = (IndexColorModel) colorModel; return indexModel.convertToIntDiscrete(img.getData(), false); } return null; } }