Java Draw Image drawImageWithClipping(Graphics g, BufferedImage img)

Here you can find the source of drawImageWithClipping(Graphics g, BufferedImage img)

Description

draw Image With Clipping

License

Open Source License

Declaration

public static void drawImageWithClipping(Graphics g, BufferedImage img) 

Method Source Code

//package com.java2s;
/*/* w ww  .j  a v  a2s  .c o  m*/
 * Copyright 2015 Laszlo Balazs-Csiki
 *
 * This file is part of Pixelitor. Pixelitor is free software: you
 * can redistribute it and/or modify it under the terms of the GNU
 * General Public License, version 3 as published by the Free
 * Software Foundation.
 *
 * Pixelitor is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Pixelitor. If not, see <http://www.gnu.org/licenses/>.
 */

import java.awt.Graphics;

import java.awt.Rectangle;

import java.awt.image.BufferedImage;

public class Main {
    public static void drawImageWithClipping(Graphics g, BufferedImage img) {
        assert img != null;

        Rectangle clipBounds = g.getClipBounds();
        int clipX = (int) clipBounds.getX();
        int clipY = (int) clipBounds.getY();
        int clipWidth = (int) clipBounds.getWidth();
        int clipHeight = (int) clipBounds.getHeight();
        int clipX2 = clipX + clipWidth;
        int clipY2 = clipY + clipHeight;
        g.drawImage(img, clipX, clipY, clipX2, clipY2, clipX, clipY, clipX2, clipY2, null);
    }
}

Related

  1. drawImageClip(Graphics g, BufferedImage image, ImageObserver observer)
  2. drawImageInOval(Graphics2D gr, Image img, Rectangle r, boolean noShrink)
  3. drawImageInPolygon(Graphics g2d, BufferedImage img, Polygon poly, double xfactor, double yfactor)
  4. drawImageInRect(Graphics g2d, BufferedImage img, Rectangle rect, double xfactor, double yfactor)
  5. drawImageInRect(Graphics2D gr, Image img, Rectangle r, boolean noShrink)
  6. drawInMiddle(Graphics g, Image image, String text)
  7. drawLabel(BufferedImage image, String text)
  8. drawNormalImage(Rectangle2D bounds, Graphics2D g2, Image image, ImageObserver observer, int imageWidth, int imageHeight)
  9. drawOnto(final BufferedImage pDestination, final Image pSource)