Example usage for javax.media.j3d ImageComponent getHeight

List of usage examples for javax.media.j3d ImageComponent getHeight

Introduction

In this page you can find the example usage for javax.media.j3d ImageComponent getHeight.

Prototype

public int getHeight() 

Source Link

Document

Retrieves the height of this image component object.

Usage

From source file:J3dSwingFrame.java

/**
 * Set the texture on our goemetry// w ww.  ja v a2 s. com
 * <P>
 * Always specified as a URL so that we may fetch it from anywhere.
 * 
 * @param url
 *            The url to the image.
 */
public void setTexture(URL url) {
    Toolkit tk = Toolkit.getDefaultToolkit();
    Image src_img = tk.createImage(url);
    BufferedImage buf_img = null;

    if (!(src_img instanceof BufferedImage)) {
        // create a component anonymous inner class to give us the image
        // observer we need to get the width and height of the source image.
        Component obs = new Component() {
        };

        int width = src_img.getWidth(obs);
        int height = src_img.getHeight(obs);

        // construct the buffered image from the source data.
        buf_img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics g = buf_img.getGraphics();
        g.drawImage(src_img, 0, 0, null);
        g.dispose();
    } else
        buf_img = (BufferedImage) src_img;

    src_img.flush();

    ImageComponent img_comp = new ImageComponent2D(ImageComponent.FORMAT_RGB, buf_img);

    texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGB, img_comp.getWidth(), img_comp.getHeight());

    appearance.setTexture(texture);

    buf_img.flush();
}