Java BufferedImage Crop cropImageRelative(BufferedImage image, double leftCropFactor, double rightCropFactor, double topCropFactor, double bottomCropFactor)

Here you can find the source of cropImageRelative(BufferedImage image, double leftCropFactor, double rightCropFactor, double topCropFactor, double bottomCropFactor)

Description

crop Image Relative

License

Open Source License

Declaration

public static BufferedImage cropImageRelative(BufferedImage image, double leftCropFactor,
            double rightCropFactor, double topCropFactor, double bottomCropFactor) 

Method Source Code

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

import java.awt.Graphics;

import java.awt.image.BufferedImage;

public class Main {
    public static BufferedImage cropImageRelative(BufferedImage image, double leftCropFactor,
            double rightCropFactor, double topCropFactor, double bottomCropFactor) {
        int lc = (int) (leftCropFactor * image.getWidth());
        int rc = (int) (rightCropFactor * image.getWidth());
        int tc = (int) (topCropFactor * image.getHeight());
        int bc = (int) (bottomCropFactor * image.getHeight());
        BufferedImage dest = new BufferedImage(image.getWidth() - (lc + rc), image.getHeight() - (tc + bc),
                BufferedImage.TYPE_BYTE_GRAY);
        Graphics g = dest.getGraphics();
        g.drawImage(image, 0, 0, image.getWidth() - (lc + rc), image.getHeight() - (tc + bc), lc, tc,
                image.getWidth() - rc, image.getHeight() - bc, null);
        g.dispose();/* www  .j  a  v  a2  s.  co m*/
        return dest;
    }
}

Related

  1. cropImage(BufferedImage image, int x, int y, int width, int height)
  2. cropImage(BufferedImage image, int x1, int y1, int x2, int y2)
  3. cropImage(BufferedImage src, int x, int y, int w, int h)
  4. cropImage(BufferedImage src, int x, int y, int w, int h)
  5. cropImage(final BufferedImage img, int x, int y, int w, int h, double xScale, double yScale)
  6. croppedCopy(BufferedImage image, int startX, int startY, int endX, int endY)
  7. cropScale(BufferedImage source, int width, int height)
  8. cropToAspectRatio(BufferedImage image, float aspect)
  9. cropToBeSameSize(BufferedImage image1, BufferedImage image2)