Java BufferedImage Crop cropImage(BufferedImage src, int x, int y, int w, int h)

Here you can find the source of cropImage(BufferedImage src, int x, int y, int w, int h)

Description

crop Image

License

Apache License

Declaration

public static BufferedImage cropImage(BufferedImage src, int x, int y, int w, int h) 

Method Source Code

//package com.java2s;
/*/*from w  ww  .  j a va2  s.c o m*/
 * Copyright 2012 Timothy Lin <lzh9102@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.awt.Graphics;

import java.awt.image.BufferedImage;

public class Main {
    public static BufferedImage cropImage(BufferedImage src, int x, int y, int w, int h) {
        BufferedImage dest = new BufferedImage(w, h, src.getType());
        Graphics g = dest.getGraphics();
        g.drawImage(src, 0, 0, w, h, x, y, x + w, y + h, null);
        g.dispose();
        return dest;
    }
}

Related

  1. cropImage(BufferedImage image, int lc, int rc, int tc, int bc)
  2. cropImage(BufferedImage image, int width, int height)
  3. cropImage(BufferedImage image, int width, int height)
  4. cropImage(BufferedImage image, int x, int y, int width, int height)
  5. cropImage(BufferedImage image, int x1, int y1, int x2, int y2)
  6. cropImage(BufferedImage src, int x, int y, int w, int h)
  7. cropImage(final BufferedImage img, int x, int y, int w, int h, double xScale, double yScale)
  8. cropImageRelative(BufferedImage image, double leftCropFactor, double rightCropFactor, double topCropFactor, double bottomCropFactor)
  9. croppedCopy(BufferedImage image, int startX, int startY, int endX, int endY)