Java BufferedImage Operation prepareModel(BufferedImage model)

Here you can find the source of prepareModel(BufferedImage model)

Description

Converts the supplied BufferedImage to a format that is appropriate to use as a model for an output image.

License

Apache License

Parameter

Parameter Description
model a parameter

Declaration

private static BufferedImage prepareModel(BufferedImage model) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.awt.image.BufferedImage;

public class Main {
    /**// w  ww.ja  v  a  2  s  .  c  o m
     * Converts the supplied {@link BufferedImage} to a format that is appropriate to use as 
     * a model for an output image. In general, this means cropping the image to ensure that 
     * only minimal image data is stored in the configuration for a 
     * <p>
     * One of the easiest ways to construct an image is to use an existing image as the template
     * to determine the correct number bands, data packing strategies, color model, etc. This
     * method is useful to convert an existing image that will serve as a  
     * 
     * @param model
     * @return
     */
    private static BufferedImage prepareModel(BufferedImage model) {
        // HACK using a buffered image as a model is a hack for reconstructing a new buffered image. 
        //      should improve the toImage method on BinaryImage
        if (model.getWidth() > 2 || model.getHeight() > 2) {
            // TODO trim to minimal image
            return model.getSubimage(0, 0, 2, 2); // discard image data
        }

        return model;
    }
}

Related

  1. output(BufferedImage image, OutputStream out)
  2. outPutImage(BufferedImage bufferedimage, String targetPath)
  3. paletteSwapARGB8(Color[] colorSet, Color clearToColorRequested, BufferedImage argbMappedBufferedImage)
  4. palettize(BufferedImage img, int maxEntries)
  5. performRescaleOperation(BufferedImage image, float scale, float offset)
  6. recolor(BufferedImage img, int newColor)
  7. recolor(BufferedImage src, Color sc)
  8. recombine(BufferedImage[][] blocks)
  9. reorientImage(BufferedImage image, boolean yAxisFlipNeeded, int cwRotationNeeded)