Java BufferedImage Operation cutToSquare(BufferedImage src)

Here you can find the source of cutToSquare(BufferedImage src)

Description

cut To Square

License

Open Source License

Declaration

public static BufferedImage cutToSquare(BufferedImage src) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.image.BufferedImage;

public class Main {
    public static BufferedImage cutToSquare(BufferedImage src) {
        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);
        } else {//from ww w. j  a  v a  2 s  .  c  o m
            int cut = (height - width) / 2;
            result = src.getSubimage(0, cut, width, width);
        }
        return result;
    }
}

Related

  1. computeBrightnesses(final BufferedImage image)
  2. computeTrimmedBounds(BufferedImage image, Rectangle tbounds)
  3. conformImageToInt(BufferedImage in)
  4. contrast(BufferedImage src, float scaleFactor)
  5. criarImagemCompativel(BufferedImage original, int largura, int altura, boolean manterQualidade)
  6. cylindricalMapping(BufferedImage img, double f)
  7. darkenImage(final BufferedImage image, final float darken)
  8. declareNewBufferedImage(int x, int y)
  9. declareNewBufferedImageAndCopy(BufferedImage img)