📄 imagecomponent2d.java
字号:
/* * $RCSfile: ImageComponent2D.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Use is subject to license terms. * * $Revision: 1.9 $ * $Date: 2007/05/23 00:32:38 $ * $State: Exp $ */package javax.media.j3d;import java.awt.image.BufferedImage;import java.awt.image.RenderedImage;import java.util.logging.Level;/** * This class defines a 2D image component. This is used for texture * images, background images and raster components of Shape3D nodes. * Prior to Java 3D 1.2, only BufferedImage objects could be used as the * input to an ImageComponent2D object. As of Java 3D 1.2, an * ImageComponent2D accepts any RenderedImage object (BufferedImage is * an implementation of the RenderedImage interface). The methods * that set/get a BufferedImage object are left in for compatibility. * The new methods that set/get a RenderedImage are a superset of the * old methods. In particular, the two set methods in the following * example are equivalent: * * <p> * <ul> * <code> * BufferedImage bi;<br> * RenderedImage ri = bi;<br> * ImageComponent2D ic;<br> * <p> * // Set the image to the specified BufferedImage<br> * ic.set(bi);<br> * <p> * // Set the image to the specified RenderedImage<br> * ic.set(ri);<br> * </code> * </ul> * * <p> * As of Java 3D 1.5, an ImageComponent2D accepts an NioImageBuffer object * as an alternative to a RenderedImage. */public class ImageComponent2D extends ImageComponent { // non-public, no parameter constructor ImageComponent2D() {} /** * Constructs a 2D image component object using the specified * format, width, and height. Default values are used for * all other parameters. The default values are as follows: * <ul> * image : null<br> * imageClass : ImageClass.BUFFERED_IMAGE<br> * </ul> * * @param format the image component format, one of: FORMAT_RGB, * FORMAT_RGBA, etc. * @param width the number of columns of pixels in this image component * object * @param height the number of rows of pixels in this image component * object * @exception IllegalArgumentException if format is invalid, or if * width or height are not positive. */ public ImageComponent2D(int format, int width, int height) { if (MasterControl.isDevLoggable(Level.FINER)) { MasterControl.getDevLogger().finer("ImageComponent - using default of byCopy"); } ((ImageComponent2DRetained)this.retained).processParams(format, width, height, 1); } /** * Constructs a 2D image component object using the specified format * and BufferedImage. A copy of the BufferedImage is made. * The image class is set to ImageClass.BUFFERED_IMAGE. * Default values are used for all other parameters. * * @param format the image component format, one of: FORMAT_RGB, * FORMAT_RGBA, etc. * @param image the BufferedImage used to create this 2D image component. * @exception IllegalArgumentException if format is invalid, or if * the width or height of the image are not positive. */ public ImageComponent2D(int format, BufferedImage image) { if (MasterControl.isDevLoggable(Level.FINER)) { MasterControl.getDevLogger().finer("ImageComponent - using default of byCopy"); } ((ImageComponent2DRetained)this.retained).processParams(format, image.getWidth(), image.getHeight(), 1); ((ImageComponent2DRetained)this.retained).set(image); } /** * Constructs a 2D image component object using the specified format * and RenderedImage. A copy of the RenderedImage is made. * The image class is set to ImageClass.BUFFERED_IMAGE. * Default values are used for all other parameters. * * @param format the image component format, one of: FORMAT_RGB, * FORMAT_RGBA, etc. * @param image the RenderedImage used to create this 2D image component * @exception IllegalArgumentException if format is invalid, or if * the width or height of the image are not positive. * * @since Java 3D 1.2 */ public ImageComponent2D(int format, RenderedImage image) { if (MasterControl.isDevLoggable(Level.FINER)) { MasterControl.getDevLogger().finer("ImageComponent - using default of byCopy"); } ((ImageComponent2DRetained)this.retained).processParams(format, image.getWidth(), image.getHeight(), 1); ((ImageComponent2DRetained)this.retained).set(image); } /** * Constructs a 2D image component object using the specified * format, width, height, byReference flag, and yUp flag. * Default values are used for all other parameters. * * @param format the image component format, one of: FORMAT_RGB, * FORMAT_RGBA, etc. * @param width the number of columns of pixels in this image component * object * @param height the number of rows of pixels in this image component * object * @param byReference a flag that indicates whether the data is copied * into this image component object or is accessed by reference. * @param yUp a flag that indicates the y-orientation of this image * component. If yUp is set to true, the origin of the image is * the lower left; otherwise, the origin of the image is the upper * left. * @exception IllegalArgumentException if format is invalid, or if * width or height are not positive. * * @since Java 3D 1.2 */ public ImageComponent2D(int format, int width, int height, boolean byReference, boolean yUp) { if (MasterControl.isDevLoggable(Level.INFO)) { if (byReference && !yUp) { MasterControl.getDevLogger().info("ImageComponent - yUp should " + "be set when using byReference, " + "otherwise an extra copy of the image will be created"); } } ((ImageComponentRetained)this.retained).setByReference(byReference); ((ImageComponentRetained)this.retained).setYUp(yUp); ((ImageComponent2DRetained)this.retained).processParams(format, width, height, 1); } /** * Constructs a 2D image component object using the specified format, * BufferedImage, byReference flag, and yUp flag. * The image class is set to ImageClass.BUFFERED_IMAGE. * * @param format the image component format, one of: FORMAT_RGB, * FORMAT_RGBA, etc. * @param image the BufferedImage used to create this 2D image component * @param byReference a flag that indicates whether the data is copied * into this image component object or is accessed by reference * @param yUp a flag that indicates the y-orientation of this image * component. If yUp is set to true, the origin of the image is * the lower left; otherwise, the origin of the image is the upper * left. * @exception IllegalArgumentException if format is invalid, or if * the width or height of the image are not positive. * * @since Java 3D 1.2 */ public ImageComponent2D(int format, BufferedImage image, boolean byReference, boolean yUp) { if (MasterControl.isDevLoggable(Level.INFO)) { if (byReference && !yUp) { MasterControl.getDevLogger().info("ImageComponent - yUp should " + "be set when using byReference, " + "otherwise an extra copy of the image will be created"); } } ((ImageComponentRetained)this.retained).setByReference(byReference); ((ImageComponentRetained)this.retained).setYUp(yUp); ((ImageComponent2DRetained)this.retained).processParams(format, image.getWidth(), image.getHeight(), 1); ((ImageComponent2DRetained)this.retained).set(image); } /** * Constructs a 2D image component object using the specified format, * RenderedImage, byReference flag, and yUp flag. * The image class is set to ImageClass.RENDERED_IMAGE if the byReferece * flag is true and the specified RenderedImage is <i>not</i> an instance * of BufferedImage. In all other cases, the image class is set to * ImageClass.BUFFERED_IMAGE. * * @param format the image component format, one of: FORMAT_RGB, * FORMAT_RGBA, etc. * @param image the RenderedImage used to create this 2D image component * @param byReference a flag that indicates whether the data is copied * into this image component object or is accessed by reference. * @param yUp a flag that indicates the y-orientation of this image * component. If yUp is set to true, the origin of the image is * the lower left; otherwise, the origin of the image is the upper * left. * @exception IllegalArgumentException if format is invalid, or if * the width or height of the image are not positive. * * @since Java 3D 1.2 */ public ImageComponent2D(int format, RenderedImage image, boolean byReference, boolean yUp) { if (MasterControl.isDevLoggable(Level.INFO)) { if (byReference && !yUp) MasterControl.getDevLogger().info("ImageComponent - yUp should " + "be set when using byReference, " + "otherwise an extra copy of the image will be created"); } ((ImageComponentRetained)this.retained).setByReference(byReference); ((ImageComponentRetained)this.retained).setYUp(yUp); ((ImageComponent2DRetained)this.retained).processParams(format, image.getWidth(), image.getHeight(), 1); ((ImageComponent2DRetained)this.retained).set(image); } /** * Constructs a 2D image component object using the specified format, * NioImageBuffer, byReference flag, and yUp flag. * The image class is set to ImageClass.NIO_IMAGE_BUFFER. * * @param format the image component format, one of: FORMAT_RGB, * FORMAT_RGBA, etc. * @param image the NioImageBuffer used to create this 2D image component * @param byReference a flag that indicates whether the data is copied * into this image component object or is accessed by reference. * @param yUp a flag that indicates the y-orientation of this image * component. If yUp is set to true, the origin of the image is * the lower left; otherwise, the origin of the image is the upper * left. * * @exception IllegalArgumentException if format is invalid, or if * the width or height of the image are not positive. * * @exception IllegalArgumentException if the byReference flag is false. * * @exception IllegalArgumentException if the yUp flag is false. * * @exception IllegalArgumentException if the number of components in format * does not match the number of components in image. * * @since Java 3D 1.5 */ public ImageComponent2D(int format, NioImageBuffer image, boolean byReference, boolean yUp) { ((ImageComponentRetained)this.retained).setByReference(byReference); ((ImageComponentRetained)this.retained).setYUp(yUp); ((ImageComponent2DRetained)this.retained).processParams(format, image.getWidth(), image.getHeight(), 1); ((ImageComponent2DRetained)this.retained).set(image); } /** * Sets this image component to the specified BufferedImage * object. * If the data access mode is not by-reference, then the * BufferedImage data is copied into this object. If * the data access mode is by-reference, then a reference to the * BufferedImage is saved, but the data is not necessarily * copied. * <p> * The image class is set to ImageClass.BUFFERED_IMAGE. * * @param image BufferedImage object containing the image. * Its size must be the same as the current size of this * ImageComponent2D object. * * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph * * @exception IllegalArgumentException if the width and height of the * specified image is not equal to the width and height of this * ImageComponent object. */ public void set(BufferedImage image) { if (isLiveOrCompiled()) { if(!this.getCapability(ALLOW_IMAGE_WRITE)) throw new CapabilityNotSetException( J3dI18N.getString("ImageComponent2D1")); } ((ImageComponent2DRetained)this.retained).set(image); } /** * Sets this image component to the specified RenderedImage * object. If the data access mode is not by-reference, the * RenderedImage data is copied into this object. If * the data access mode is by-reference, a reference to the * RenderedImage is saved, but the data is not necessarily * copied. * <p> * The image class is set to ImageClass.RENDERED_IMAGE if the the * data access mode is by-reference and the specified * RenderedImage is <i>not</i> an instance of BufferedImage. In all * other cases, the image class is set to ImageClass.BUFFERED_IMAGE. * * @param image RenderedImage object containing the image. * Its size must be the same as the current size of this * ImageComponent2D object. * * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph * * @exception IllegalArgumentException if the width and height of the * specified image is not equal to the width and height of this * ImageComponent object. * * @since Java 3D 1.2 */ public void set(RenderedImage image) { if (isLiveOrCompiled()) { if(!this.getCapability(ALLOW_IMAGE_WRITE)) throw new CapabilityNotSetException( J3dI18N.getString("ImageComponent2D1")); } ((ImageComponent2DRetained)this.retained).set(image); } /** * Sets this image component to the specified NioImageBuffer * object. If the data access mode is not by-reference, the * NioImageBuffer data is copied into this object. If * the data access mode is by-reference, a reference to the * NioImageBuffer is saved, but the data is not necessarily * copied. * <p> * The image class is set to ImageClass.NIO_IMAGE_BUFFER. * * @param image NioImageBuffer object containing the image. * Its size must be the same as the current size of this
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -