Java BufferedImage Crop crop(BufferedImage source, int startX, int startY, int endX, int endY)

Here you can find the source of crop(BufferedImage source, int startX, int startY, int endX, int endY)

Description

crop

License

Open Source License

Declaration

public static BufferedImage crop(BufferedImage source, int startX,
        int startY, int endX, int endY) 

Method Source Code

//package com.java2s;

import java.awt.image.BufferedImage;

public class Main {

    public static BufferedImage crop(BufferedImage source, int startX,
            int startY, int endX, int endY) {
        int width = source.getWidth();
        int height = source.getHeight();

        if (startX <= -1) {
            startX = 0;/*  w w w  .ja v  a2 s  .  c  o  m*/
        }
        if (startY <= -1) {
            startY = 0;
        }
        if (endX <= -1) {
            endX = width - 1;
        }
        if (endY <= -1) {
            endY = height - 1;
        }
        BufferedImage result = new BufferedImage(endX, endY,
                source.getType());
        for (int y = startY; y < endY + startY; y++) {
            for (int x = startX; x < endX + startX; x++) {
                int rgb = source.getRGB(x, y);
                result.setRGB(x - startX, y - startY, rgb);
            }
        }
        return result;
    }
}

Related

  1. autoCrop(BufferedImage source, double tolerance)
  2. crop(BufferedImage image, Rectangle clip)
  3. crop(BufferedImage input, int x, int y, int width, int height)
  4. crop(BufferedImage original, int newSize)
  5. crop(BufferedImage source, File to, int x1, int y1, int x2, int y2)
  6. crop(BufferedImage src, int width, int height)
  7. crop(BufferedImage src, int x, int y, int width, int height)
  8. crop(BufferedImage src, Rectangle rect)
  9. crop(final Raster src, final long tx, final long ty, final long minTx, final long maxTy, final int tilesize)