Java Utililty Methods BufferedImage Operation

List of utility methods to do BufferedImage Operation

Description

The list of methods to do BufferedImage Operation are organized into topic(s).

Method

BufferedImagecomposite(BufferedImage bg, BufferedImage fg)
composite
BufferedImage result = copyImage(bg);
Graphics g = result.getGraphics();
g.drawImage(fg, 0, 0, null);
g.dispose();
return result;
double[][]computeBrightnesses(final BufferedImage image)
compute Brightnesses
final int width = image.getWidth();
final int height = image.getHeight();
final double[][] brightnesses = new double[width][height];
for (int i = 0; i < width; ++i) {
    for (int j = 0; j < height; ++j) {
        brightnesses[i][j] = getBrightness(image, i, j);
return brightnesses;
voidcomputeTrimmedBounds(BufferedImage image, Rectangle tbounds)
Computes the bounds of the smallest rectangle that contains all non-transparent pixels of this image.
int width = image.getWidth(), height = image.getHeight();
int firstrow = -1, lastrow = -1, minx = width, maxx = 0;
for (int yy = 0; yy < height; yy++) {
    int firstidx = -1, lastidx = -1;
    for (int xx = 0; xx < width; xx++) {
        int argb = image.getRGB(xx, yy);
        if ((argb >> 24) == 0) {
            continue;
...
BufferedImageconformImageToInt(BufferedImage in)
conform Image To Int
return convertImage(in, BufferedImage.TYPE_INT_RGB);
BufferedImagecontrast(BufferedImage src, float scaleFactor)
Contrasts image.
RescaleOp rop = new RescaleOp(scaleFactor, 0, null);
return rop.filter(src, null);
BufferedImagecriarImagemCompativel(BufferedImage original, int largura, int altura, boolean manterQualidade)
criar Imagem Compativel
GraphicsConfiguration graphicsConfiguration = GraphicsEnvironment.getLocalGraphicsEnvironment()
        .getDefaultScreenDevice().getDefaultConfiguration();
BufferedImage imagemCompativel = graphicsConfiguration.createCompatibleImage(largura, altura,
        original.getTransparency());
Graphics2D g = (Graphics2D) imagemCompativel.getGraphics();
if (manterQualidade) {
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g.drawImage(original, 0, 0, largura, altura, null);
g.dispose();
return imagemCompativel;
BufferedImagecutToSquare(BufferedImage src)
cut To Square
int width = src.getWidth();
int height = src.getHeight();
if (width == height)
    return src;
BufferedImage result = null;
if (width > height) {
    int cut = (width - height) / 2;
    result = src.getSubimage(cut, 0, height, height);
...
BufferedImagecylindricalMapping(BufferedImage img, double f)
cylindrical Mapping
if (img == null) {
    return null;
int w = img.getWidth();
int h = img.getHeight();
BufferedImage out = new BufferedImage(w, h, img.getType());
int x0 = (int) Math.floor(w / 2) + 1;
int y0 = (int) Math.floor(h / 2) + 1;
...
voiddarkenImage(final BufferedImage image, final float darken)
Darkens specified BufferedImage
final Graphics2D g2d = image.createGraphics();
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, darken));
g2d.setPaint(Color.BLACK);
g2d.fillRect(0, 0, image.getWidth(), image.getHeight());
g2d.dispose();
BufferedImagedeclareNewBufferedImage(int x, int y)
declare New Buffered Image
BufferedImage imgOut = new BufferedImage(x, y, BufferedImage.TYPE_INT_RGB);
return imgOut;