📄 raster.java
字号:
} /** * Create a compatible WritableRaster with location (minX, minY) * and size (width, height) specified by rect, a * new SampleModel, and a new initialized DataBuffer. * @param rect a <code>Rectangle</code> that specifies the size and * location of the <code>WritableRaster</code> * @return a compatible <code>WritableRaster</code> with the specified * size and location and a new sample model and data buffer. * @throws RasterFormatException if <code>rect</code> has width * or height less than or equal to zero, or computing either * <code>rect.x + rect.width</code> or * <code>rect.y + rect.height</code> results in integer * overflow * @throws NullPointerException if <code>rect<code> is null */ public WritableRaster createCompatibleWritableRaster(Rectangle rect) { if (rect == null) { throw new NullPointerException("Rect cannot be null"); } return createCompatibleWritableRaster(rect.x, rect.y, rect.width, rect.height); } /** * Create a compatible WritableRaster with the specified * location (minX, minY) and size (width, height), a * new SampleModel, and a new initialized DataBuffer. * @param x, y the coordinates of the upper-left corner of * the <code>WritableRaster</code> * @param w the specified width of the <code>WritableRaster</code> * @param h the specified height of the <code>WritableRaster</code> * @return a compatible <code>WritableRaster</code> with the specified * size and location and a new sample model and data buffer. * @throws RasterFormatException if <code>w</code> or <code>h</code> * is less than or equal to zero, or computing either * <code>x + w</code> or * <code>y + h</code> results in integer * overflow */ public WritableRaster createCompatibleWritableRaster(int x, int y, int w, int h) { WritableRaster ret = createCompatibleWritableRaster(w, h); return ret.createWritableChild(0,0,w,h,x,y,null); } /** * Create a Raster with the same size, SampleModel and DataBuffer * as this one, but with a different location. The new Raster * will possess a reference to the current Raster, accessible * through its getParent() method. * * @param childMinX, childMinY coordinates of the upper-left * corner of the new <code>Raster</code> * @return a new <code>Raster</code> with the same size, SampleModel, * and DataBuffer as this <code>Raster</code>, but with the * specified location. * @throws RasterFormatException if computing either * <code>childMinX + this.getWidth()</code> or * <code>childMinY + this.getHeight()</code> results in integer * overflow */ public Raster createTranslatedChild(int childMinX, int childMinY) { return createChild(minX,minY,width,height, childMinX,childMinY,null); } /** * Returns a new Raster which shares all or part of this Raster's * DataBuffer. The new Raster will possess a reference to the * current Raster, accessible through its getParent() method. * * <p> The parentX, parentY, width and height parameters * form a Rectangle in this Raster's coordinate space, * indicating the area of pixels to be shared. An error will * be thrown if this Rectangle is not contained with the bounds * of the current Raster. * * <p> The new Raster may additionally be translated to a * different coordinate system for the plane than that used by the current * Raster. The childMinX and childMinY parameters give the new * (x, y) coordinate of the upper-left pixel of the returned * Raster; the coordinate (childMinX, childMinY) in the new Raster * will map to the same pixel as the coordinate (parentX, parentY) * in the current Raster. * * <p> The new Raster may be defined to contain only a subset of * the bands of the current Raster, possibly reordered, by means * of the bandList parameter. If bandList is null, it is taken to * include all of the bands of the current Raster in their current * order. * * <p> To create a new Raster that contains a subregion of the current * Raster, but shares its coordinate system and bands, * this method should be called with childMinX equal to parentX, * childMinY equal to parentY, and bandList equal to null. * * @param parentX, parentY coordinates of the upper-left corner * in this Raster's coordinates * @param width Width of the region starting at (parentX, parentY) * @param height Height of the region starting at (parentX, parentY). * @param childMinX, childMinY coordinates of the upper-left corner * of the returned Raster * @param bandList Array of band indices, or null to use all bands * @return a new <code>Raster</code>. * @exception RasterFormatException if the specified subregion is outside * of the raster bounds. * @throws RasterFormatException if <code>width</code> or * <code>height</code> * is less than or equal to zero, or computing any of * <code>parentX + width</code>, <code>parentY + height</code>, * <code>childMinX + width</code>, or * <code>childMinY + height</code> results in integer * overflow */ public Raster createChild(int parentX, int parentY, int width, int height, int childMinX, int childMinY, int bandList[]) { if (parentX < this.minX) { throw new RasterFormatException("parentX lies outside raster"); } if (parentY < this.minY) { throw new RasterFormatException("parentY lies outside raster"); } if ((parentX + width < parentX) || (parentX + width > this.width + this.minX)) { throw new RasterFormatException("(parentX + width) is outside raster"); } if ((parentY + height < parentY) || (parentY + height > this.height + this.minY)) { throw new RasterFormatException("(parentY + height) is outside raster"); } SampleModel subSampleModel; // Note: the SampleModel for the child Raster should have the same // width and height as that for the parent, since it represents // the physical layout of the pixel data. The child Raster's width // and height represent a "virtual" view of the pixel data, so // they may be different than those of the SampleModel. if (bandList == null) { subSampleModel = sampleModel; } else { subSampleModel = sampleModel.createSubsetSampleModel(bandList); } int deltaX = childMinX - parentX; int deltaY = childMinY - parentY; return new Raster(subSampleModel, dataBuffer, new Rectangle(childMinX, childMinY, width, height), new Point(sampleModelTranslateX + deltaX, sampleModelTranslateY + deltaY), this); } /** * Returns the bounding Rectangle of this Raster. This function returns * the same information as getMinX/MinY/Width/Height. * @return the bounding box of this <code>Raster</code>. */ public Rectangle getBounds() { return new Rectangle(minX, minY, width, height); } /** Returns the minimum valid X coordinate of the Raster. * @return the minimum x coordinate of this <code>Raster</code>. */ final public int getMinX() { return minX; } /** Returns the minimum valid Y coordinate of the Raster. * @return the minimum y coordinate of this <code>Raster</code>. */ final public int getMinY() { return minY; } /** Returns the width in pixels of the Raster. * @return the width of this <code>Raster</code>. */ final public int getWidth() { return width; } /** Returns the height in pixels of the Raster. * @return the height of this <code>Raster</code>. */ final public int getHeight() { return height; } /** Returns the number of bands (samples per pixel) in this Raster. * @return the number of bands of this <code>Raster</code>. */ final public int getNumBands() { return numBands; } /** * Returns the number of data elements needed to transfer one pixel * via the getDataElements and setDataElements methods. When pixels * are transferred via these methods, they may be transferred in a * packed or unpacked format, depending on the implementation of the * underlying SampleModel. Using these methods, pixels are transferred * as an array of getNumDataElements() elements of a primitive type given * by getTransferType(). The TransferType may or may not be the same * as the storage data type of the DataBuffer. * @return the number of data elements. */ final public int getNumDataElements() { return sampleModel.getNumDataElements(); } /** * Returns the TransferType used to transfer pixels via the * getDataElements and setDataElements methods. When pixels * are transferred via these methods, they may be transferred in a * packed or unpacked format, depending on the implementation of the * underlying SampleModel. Using these methods, pixels are transferred * as an array of getNumDataElements() elements of a primitive type given * by getTransferType(). The TransferType may or may not be the same * as the storage data type of the DataBuffer. The TransferType will * be one of the types defined in DataBuffer. * @return this transfer type. */ final public int getTransferType() { return sampleModel.getTransferType(); } /** Returns the DataBuffer associated with this Raster. * @return the <code>DataBuffer</code> of this <code>Raster</code>. */ public DataBuffer getDataBuffer() { return dataBuffer; } /** Returns the SampleModel that describes the layout of the image data. * @return the <code>SampleModel</code> of this <code>Raster</code>. */ public SampleModel getSampleModel() { return sampleModel; } /** * Returns data for a single pixel in a primitive array of type * TransferType. For image data supported by the Java 2D(tm) API, * this will be one of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, * DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT, DataBuffer.TYPE_FLOAT, * or DataBuffer.TYPE_DOUBLE. Data may be returned in a packed format, * thus increasing efficiency for data transfers. * An ArrayIndexOutOfBoundsException may be thrown * if the coordinates are not in bounds. However, explicit bounds * checking is not guaranteed. * A ClassCastException will be thrown if the input object is non null * and references anything other than an array of TransferType. * @see java.awt.image.SampleModel#getDataElements(int, int, Object, DataBuffer) * @param x, y the coordinates of the pixel location * @param outData An object reference to an array of type defined by * getTransferType() and length getNumDataElements(). * If null, an array of appropriate type and size will be * allocated * @return An object reference to an array of type defined by * getTransferType() with the requested pixel data. * * @throws ArrayIndexOutOfBoundsException if the coordinates are not * in bounds, or if outData is too small to hold the output. */ public Object getDataElements(int x, int y, Object outData) { return sampleModel.getDataElements(x - sampleModelTranslateX, y - sampleModelTranslateY, outData, dataBuffer); } /** * Returns the pixel data for the specified rectangle of pixels in a * primitive array of type TransferType. * For image data supported by the Java 2D API, this * will be one of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, * DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT, DataBuffer.TYPE_FLOAT, * or DataBuffer.TYPE_DOUBLE. Data may be returned in a packed format, * thus increasing efficiency for data transfers. * An ArrayIndexOutOfBoundsException may be thrown * if the coordinates are not in bounds. However, explicit bounds * checking is not guaranteed. * A ClassCastException will be thrown if the input object is non null * and references anything other than an array of TransferType. * @see java.awt.image.SampleModel#getDataElements(int, int, int, int, Object, DataBuffer) * @param x, y the coordinates of the upper-left pixel location * @param w Width of
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -