⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bufferedimage.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
     *          no information about its immediate sources, or an empty     *          <code>Vector</code> if this <code>BufferedImage</code>        *          has no immediate sources.      */    public Vector getSources() {        return null;    }    /**      * Returns an array of names recognized by      * {@link #getProperty(String) getProperty(String)}     * or <code>null</code>, if no property names are recognized.     * @return a <code>String</code> array containing all of the property     *          names that <code>getProperty(String)</code> recognizes;     *		or <code>null</code> if no property names are recognized.     */    public String[] getPropertyNames() {         return null;    }    /**      * Returns the minimum x coordinate of this     * <code>BufferedImage</code>.  This is always zero.     * @return the minimum x coordinate of this     *          <code>BufferedImage</code>.     */    public int getMinX() {        return raster.getMinX();    }    /**      * Returns the minimum y coordinate of this     * <code>BufferedImage</code>.  This is always zero.     * @return the minimum y coordinate of this     *          <code>BufferedImage</code>.     */    public int getMinY() {        return raster.getMinY();    }    /**      * Returns the <code>SampleModel</code> associated with this     * <code>BufferedImage</code>.      * @return the <code>SampleModel</code> of this     *          <code>BufferedImage</code>.     */    public SampleModel getSampleModel() {        return raster.getSampleModel();    }    /**     * Returns the number of tiles in the x direction.     * This is always one.     * @return the number of tiles in the x direction.     */    public int getNumXTiles() {        return 1;    }    /**     * Returns the number of tiles in the y direction.     * This is always one.     * @return the number of tiles in the y direction.     */    public int getNumYTiles() {        return 1;    }    /**     * Returns the minimum tile index in the x direction.     * This is always zero.     * @return the minimum tile index in the x direction.     */    public int getMinTileX() {        return 0;    }    /**     * Returns the minimum tile index in the y direction.     * This is always zero.     * @return the mininum tile index in the y direction.     */    public int getMinTileY() {        return 0;    }    /**     * Returns the tile width in pixels.     * @return the tile width in pixels.     */    public int getTileWidth() {       return raster.getWidth();    }    /**     * Returns the tile height in pixels.     * @return the tile height in pixels.     */    public int getTileHeight() {       return raster.getHeight();    }    /**     * Returns the x offset of the tile grid relative to the origin,     * For example, the x coordinate of the location of tile      * (0,&nbsp;0).  This is always zero.     * @return the x offset of the tile grid.     */    public int getTileGridXOffset() {        return raster.getSampleModelTranslateX();    }        /**     * Returns the y offset of the tile grid relative to the origin,     * For example, the y coordinate of the location of tile      * (0,&nbsp;0).  This is always zero.     * @return the y offset of the tile grid.     */    public int getTileGridYOffset() {        return raster.getSampleModelTranslateY();    }        /**      * Returns tile (<code>tileX</code>,&nbsp;<code>tileY</code>).  Note     * that <code>tileX</code> and <code>tileY</code> are indices     * into the tile array, not pixel locations.  The <code>Raster</code>      * that is returned is live, which means that it is updated if the     * image is changed.     * @param tileX the x index of the requested tile in the tile array     * @param tileY the y index of the requested tile in the tile array     * @return a <code>Raster</code> that is the tile defined by the     *          arguments <code>tileX</code> and <code>tileY</code>.      * @exception <code>ArrayIndexOutOfBoundsException</code> if both     * 		<code>tileX</code> and <code>tileY</code> are not     *		equal to 0     */    public Raster getTile(int tileX, int tileY) {        if (tileX == 0 && tileY == 0) {            return raster;        }        throw new ArrayIndexOutOfBoundsException("BufferedImages only have"+             " one tile with index 0,0");    }    /**      * Returns the image as one large tile.  The <code>Raster</code>      * returned is a copy of the image data is not updated if the     * image is changed.     * @return a <code>Raster</code> that is a copy of the image data.      * @see #setData(Raster)     */    public Raster getData() {        // REMIND : this allocates a whole new tile if raster is a        // subtile.  (It only copies in the requested area)        // We should do something smarter.        int width = raster.getWidth();        int height = raster.getHeight();        int startX = raster.getMinX();        int startY = raster.getMinY();        WritableRaster wr =            Raster.createWritableRaster(raster.getSampleModel(),                         new Point(raster.getSampleModelTranslateX(),                                   raster.getSampleModelTranslateY()));        Object tdata = null;        for (int i = startY; i < startY+height; i++)  {            tdata = raster.getDataElements(startX,i,width,1,tdata);            wr.setDataElements(startX,i,width,1, tdata);        }        return wr;    }        /**      * Computes and returns an arbitrary region of the      * <code>BufferedImage</code>.  The <code>Raster</code> returned is a     * copy of the image data and is not updated if the image is     * changed.     * @param rect the region of the <code>BufferedImage</code> to be     * returned.     * @return a <code>Raster</code> that is a copy of the image data of     *          the specified region of the <code>BufferedImage</code>      * @see #setData(Raster)     */    public Raster getData(Rectangle rect) {        SampleModel sm = raster.getSampleModel();        SampleModel nsm = sm.createCompatibleSampleModel(rect.width,                                                         rect.height);        WritableRaster wr = Raster.createWritableRaster(nsm,                                                  rect.getLocation());        int width = rect.width;        int height = rect.height;        int startX = rect.x;        int startY = rect.y;        Object tdata = null;        for (int i = startY; i < startY+height; i++)  {            tdata = raster.getDataElements(startX,i,width,1,tdata);            wr.setDataElements(startX,i,width,1, tdata);        }        return wr;    }     /**      * Computes an arbitrary rectangular region of the      * <code>BufferedImage</code> and copies it into a specified     * <code>WritableRaster</code>.  The region to be computed is     * determined from the bounds of the specified     * <code>WritableRaster</code>.  The specified      * <code>WritableRaster</code> must have a     * <code>SampleModel</code> that is compatible with this image.  If     * <code>outRaster</code> is <code>null</code>,     * an appropriate <code>WritableRaster</code> is created.     * @param outRaster a <code>WritableRaster</code> to hold the returned     *          part of the image, or <code>null</code>     * @return a reference to the supplied or created     *          <code>WritableRaster</code>.      */    public WritableRaster copyData(WritableRaster outRaster) {        if (outRaster == null) {            return (WritableRaster) getData();        }        int width = outRaster.getWidth();        int height = outRaster.getHeight();        int startX = outRaster.getMinX();        int startY = outRaster.getMinY();        Object tdata = null;        for (int i = startY; i < startY+height; i++)  {            tdata = raster.getDataElements(startX,i,width,1,tdata);            outRaster.setDataElements(startX,i,width,1, tdata);        }        return outRaster;    }  /**     * Sets a rectangular region of the image to the contents of the     * specified <code>Raster</code> <code>r</code>, which is     * assumed to be in the same coordinate space as the     * <code>BufferedImage</code>. The operation is clipped to the bounds     * of the <code>BufferedImage</code>.     * @param r the specified <code>Raster</code>      * @see #getData     * @see #getData(Rectangle)    */    public void setData(Raster r) {        int width = r.getWidth();        int height = r.getHeight();        int startX = r.getMinX();        int startY = r.getMinY();         int[] tdata = null;        // Clip to the current Raster        Rectangle rclip = new Rectangle(startX, startY, width, height);        Rectangle bclip = new Rectangle(0, 0, raster.width, raster.height);        Rectangle intersect = rclip.intersection(bclip);        if (intersect.isEmpty()) {            return;        }        width = intersect.width;        height = intersect.height;        startX = intersect.x;        startY = intersect.y;        // remind use get/setDataElements for speed if Rasters are        // compatible        for (int i = startY; i < startY+height; i++)  {            tdata = r.getPixels(startX,i,width,1,tdata);            raster.setPixels(startX,i,width,1, tdata);        }    }  /**   * Adds a tile observer.  If the observer is already present,   * it receives multiple notifications.   * @param to the specified {@link TileObserver}   */    public void addTileObserver (TileObserver to) {    }      /**   * Removes a tile observer.  If the observer was not registered,   * nothing happens.  If the observer was registered for multiple   * notifications, it is now registered for one fewer notification.   * @param to the specified <code>TileObserver</code>.   */    public void removeTileObserver (TileObserver to) {    }       /**     * Returns whether or not a tile is currently checked out for writing.     * @param tileX the x index of the tile.     * @param tileY the y index of the tile.     * @return <code>true</code> if the tile specified by the specified     *          indices is checked out for writing; <code>false</code>     *          otherwise.      * @exception <code>ArrayIndexOutOfBoundsException</code> if both     * 		<code>tileX</code> and <code>tileY</code> are not equal     *		to 0     */    public boolean isTileWritable (int tileX, int tileY) {        if (tileX == 0 && tileY == 0) {            return true;        }        throw new IllegalArgumentException("Only 1 tile in image");    }        /**     * Returns an array of {@link Point} objects indicating which tiles     * are checked out for writing.  Returns <code>null</code> if none are     * checked out.     * @return a <code>Point</code> array that indicates the tiles that     *          are checked out for writing, or <code>null</code> if no     *          tiles are checked out for writing.      */    public Point[] getWritableTileIndices() {        Point[] p = new Point[1];        p[0] = new Point(0, 0);        return p;    }        /**     * Returns whether or not any tile is checked out for writing.     * Semantically equivalent to      * <pre>     * (getWritableTileIndices() != null).     * </pre>     * @return <code>true</code> if any tile is checked out for writing;     *          <code>false</code> otherwise.      */    public boolean hasTileWriters () {        return true;    }  /**   * Checks out a tile for writing.  All registered    * <code>TileObservers</code> are notified when a tile goes from having   * no writers to having one writer.   * @param tileX the x index of the tile   * @param tileY the y index of the tile   * @return a <code>WritableRaster</code> that is the tile, indicated by   *            the specified indices, to be checked out for writing.    */    public WritableRaster getWritableTile (int tileX, int tileY) {        return raster;    }    /**   * Relinquishes permission to write to a tile.  If the caller    * continues to write to the tile, the results are undefined.   * Calls to this method should only appear in matching pairs   * with calls to {@link #getWritableTile(int, int) getWritableTile(int, int)}.  Any other leads   * to undefined results.  All registered <code>TileObservers</code>   * are notified when a tile goes from having one writer to having no   * writers.   * @param tileX the x index of the tile   * @param tileY the y index of the tile   */    public void releaseWritableTile (int tileX, int tileY) {    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -