Java BufferedImage Crop cropBoundingBox(Rectangle r, int width, int height)

Here you can find the source of cropBoundingBox(Rectangle r, int width, int height)

Description

crop Bounding Box

License

Open Source License

Declaration

public static Rectangle cropBoundingBox(Rectangle r, int width,
            int height) 

Method Source Code

//package com.java2s;
/*****************************************************************************
 ** ANGRYBIRDS AI AGENT FRAMEWORK/* www. j a  va2  s.com*/
 ** Copyright (c) 2013,XiaoYu (Gary) Ge, Stephen Gould,Jochen Renz
 **  Sahan Abeyasinghe, Jim Keys, Kar-Wai Lim, Zain Mubashir,  Andrew Wang, Peng Zhang
 ** All rights reserved.
 **This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. 
 **To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ 
 *or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
 *****************************************************************************/

import java.awt.*;

public class Main {
    public static Rectangle cropBoundingBox(Rectangle r, Image img) {
        return cropBoundingBox(r, img.getWidth(null), img.getHeight(null));
    }

    public static Rectangle cropBoundingBox(Rectangle r, int width,
            int height) {
        if (r.x < 0)
            r.x = 0;
        if (r.y < 0)
            r.y = 0;
        if ((r.x + r.width) > width)
            r.width = width - r.x;
        if ((r.y + r.height) > height)
            r.height = height - r.y;

        return r;
    }
}

Related

  1. crop(BufferedImage src, Rectangle rect)
  2. crop(final Raster src, final long tx, final long ty, final long minTx, final long maxTy, final int tilesize)
  3. crop4Square(BufferedImage source, File to, int size)
  4. cropAndScaleImage(BufferedImage image, int cropX, int cropY, int cropW, int cropH, int scaleW, int scaleH)
  5. cropBottomTransparent(BufferedImage img)
  6. cropImage(BufferedImage image, int cropWidth, int cropHeight)
  7. cropImage(BufferedImage image, int fromX, int fromY, int width, int height)
  8. cropImage(BufferedImage image, int lc, int rc, int tc, int bc)
  9. cropImage(BufferedImage image, int width, int height)