draw Normal Image - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Effect

Description

draw Normal Image

Demo Code

/**//from ww w.  j a  va 2s.  c o m
 * Copyright 1998-2008, CHISEL Group, University of Victoria, Victoria, BC, Canada.
 * All rights reserved.
 */
//package com.java2s;

import java.awt.Graphics2D;
import java.awt.Image;

import java.awt.geom.Rectangle2D;

import java.awt.image.ImageObserver;

public class Main {
    public static void drawNormalImage(Rectangle2D bounds, Graphics2D g2,
            Image image, ImageObserver observer, int imageWidth,
            int imageHeight) {
        int x = (int) bounds.getX();
        int y = (int) bounds.getY();
        int w = Math.min(imageWidth, (int) bounds.getWidth());
        int h = Math.min(imageHeight, (int) bounds.getHeight());

        // no scaling is done here - note it uses only (x, y) coordinates, not width and height
        g2.drawImage(image, x, y, x + w, y + h, 0, 0, w, h, /* g2.getColor(),*/
                observer);
    }
}

Related Tutorials