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

📄 raster.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * @param dataBuffer the <code>DataBuffer</code> that contains the     *        image data     * @param w         the width in pixels of the image data     * @param h         the height in pixels of the image data     * @param scanlineStride the line stride of the image data     * @param pixelStride the pixel stride of the image data     * @param bandOffsets the offsets of all bands     * @param location  the upper-left corner of the <code>Raster</code>     * @return a WritableRaster object with the specified     *         <code>DataBuffer</code>, width, height, scanline stride,      *         pixel stride and band offsets.     * @throws RasterFormatException if <code>w</code> or <code>h</code>     *         is less than or equal to zero, or computing either     *         <code>location.x + w</code> or     *         <code>location.y + h</code> results in integer     *         overflow     * @throws IllegalArgumentException if <code>dataType</code> is not     *         one of the supported data types, which are     *         <code>DataBuffer.TYPE_BYTE</code>,      *         <code>DataBuffer.TYPE_USHORT</code>     * @throws RasterFormatException if <code>dataBuffer</code> has more     *         than one bank.     * @throws NullPointerException if <code>dataBuffer</code> is null     */    public static WritableRaster createInterleavedRaster(DataBuffer dataBuffer,                                                         int w, int h,                                                         int scanlineStride,                                                         int pixelStride,                                                         int bandOffsets[],                                                         Point location) {        if (dataBuffer == null) {            throw new NullPointerException("DataBuffer cannot be null");        }        if (location == null) {            location = new Point(0, 0);        }        int dataType = dataBuffer.getDataType();        PixelInterleavedSampleModel csm =            new PixelInterleavedSampleModel(dataType, w, h,                                            pixelStride,                                            scanlineStride,                                            bandOffsets);        switch(dataType) {        case DataBuffer.TYPE_BYTE:            return new ByteInterleavedRaster(csm, dataBuffer, location);        case DataBuffer.TYPE_USHORT:            return new ShortInterleavedRaster(csm, dataBuffer, location);        default:            throw new IllegalArgumentException("Unsupported data type " +                                                dataType);        }    }    /**     * Creates a Raster based on a BandedSampleModel with the     * specified DataBuffer, width, height, scanline stride, bank     * indices, and band offsets.  The number of bands is inferred     * from bankIndices.length and bandOffsets.length, which must be     * the same.  The upper left corner of the Raster is given by the     * location argument.  If location is null, (0, 0) will be used.     * @param dataBuffer the <code>DataBuffer</code> that contains the     *        image data     * @param w         the width in pixels of the image data     * @param h         the height in pixels of the image data     * @param scanlineStride the line stride of the image data     * @param bankIndices the bank indices for each band     * @param bandOffsets the offsets of all bands     * @param location  the upper-left corner of the <code>Raster</code>     * @return a WritableRaster object with the specified     *         <code>DataBuffer</code>, width, height, scanline stride,      *         bank indices and band offsets.     * @throws RasterFormatException if <code>w</code> or <code>h</code>     *         is less than or equal to zero, or computing either     *         <code>location.x + w</code> or     *         <code>location.y + h</code> results in integer     *         overflow     * @throws IllegalArgumentException if <code>dataType</code> is not     *         one of the supported data types, which are     *         <code>DataBuffer.TYPE_BYTE</code>,      *         <code>DataBuffer.TYPE_USHORT</code>      *         or <code>DataBuffer.TYPE_INT</code>     * @throws NullPointerException if <code>dataBuffer</code> is null     */    public static WritableRaster createBandedRaster(DataBuffer dataBuffer,                                                    int w, int h,                                                    int scanlineStride,                                                    int bankIndices[],                                                    int bandOffsets[],                                                    Point location) {        if (dataBuffer == null) {            throw new NullPointerException("DataBuffer cannot be null");        }        if (location == null) {           location = new Point(0,0);        }        int dataType = dataBuffer.getDataType();        int bands = bankIndices.length;        if (bandOffsets.length != bands) {            throw new IllegalArgumentException(                                   "bankIndices.length != bandOffsets.length");        }        BandedSampleModel bsm =            new BandedSampleModel(dataType, w, h,                                  scanlineStride,                                  bankIndices, bandOffsets);        switch(dataType) {        case DataBuffer.TYPE_BYTE:            return new ByteBandedRaster(bsm, dataBuffer, location);        case DataBuffer.TYPE_USHORT:            return new ShortBandedRaster(bsm, dataBuffer, location);        case DataBuffer.TYPE_INT:            return new SunWritableRaster(bsm, dataBuffer, location);        default:            throw new IllegalArgumentException("Unsupported data type " +                                                dataType);        }    }    /**     * Creates a Raster based on a SinglePixelPackedSampleModel with     * the specified DataBuffer, width, height, scanline stride, and     * band masks.  The number of bands is inferred from bandMasks.length.     * The upper left corner of the Raster is given by     * the location argument.  If location is null, (0, 0) will be used.     * @param dataBuffer the <code>DataBuffer</code> that contains the     *        image data     * @param w         the width in pixels of the image data     * @param h         the height in pixels of the image data     * @param scanlineStride the line stride of the image data     * @param bandMasks an array containing an entry for each band     * @param location  the upper-left corner of the <code>Raster</code>     * @return a WritableRaster object with the specified     *         <code>DataBuffer</code>, width, height, scanline stride,      *         and band masks.     * @throws RasterFormatException if <code>w</code> or <code>h</code>     *         is less than or equal to zero, or computing either     *         <code>location.x + w</code> or     *         <code>location.y + h</code> results in integer     *         overflow     * @throws IllegalArgumentException if <code>dataType</code> is not     *         one of the supported data types, which are     *         <code>DataBuffer.TYPE_BYTE</code>,      *         <code>DataBuffer.TYPE_USHORT</code>      *         or <code>DataBuffer.TYPE_INT</code>     * @throws RasterFormatException if <code>dataBuffer</code> has more     *         than one bank.     * @throws NullPointerException if <code>dataBuffer</code> is null     */    public static WritableRaster createPackedRaster(DataBuffer dataBuffer,                                                    int w, int h,                                                    int scanlineStride,                                                    int bandMasks[],                                                    Point location) {        if (dataBuffer == null) {            throw new NullPointerException("DataBuffer cannot be null");        }        if (location == null) {           location = new Point(0,0);        }        int dataType = dataBuffer.getDataType();        SinglePixelPackedSampleModel sppsm =            new SinglePixelPackedSampleModel(dataType, w, h, scanlineStride,                                             bandMasks);        switch(dataType) {        case DataBuffer.TYPE_BYTE:            return new ByteInterleavedRaster(sppsm, dataBuffer, location);        case DataBuffer.TYPE_USHORT:            return new ShortInterleavedRaster(sppsm, dataBuffer, location);        case DataBuffer.TYPE_INT:            return new IntegerInterleavedRaster(sppsm, dataBuffer, location);        default:            throw new IllegalArgumentException("Unsupported data type " +                                                dataType);        }    }    /**     * Creates a Raster based on a MultiPixelPackedSampleModel with the     * specified DataBuffer, width, height, and bits per pixel.  The upper     * left corner of the Raster is given by the location argument.  If     * location is null, (0, 0) will be used.     * @param dataBuffer the <code>DataBuffer</code> that contains the     *        image data     * @param w         the width in pixels of the image data     * @param h         the height in pixels of the image data     * @param bitsPerPixel the number of bits for each pixel     * @param location  the upper-left corner of the <code>Raster</code>     * @return a WritableRaster object with the specified     *         <code>DataBuffer</code>, width, height, and     *         bits per pixel.     * @throws RasterFormatException if <code>w</code> or <code>h</code>     *         is less than or equal to zero, or computing either     *         <code>location.x + w</code> or     *         <code>location.y + h</code> results in integer     *         overflow     * @throws IllegalArgumentException if <code>dataType</code> is not     *         one of the supported data types, which are     *         <code>DataBuffer.TYPE_BYTE</code>,      *         <code>DataBuffer.TYPE_USHORT</code>      *         or <code>DataBuffer.TYPE_INT</code>     * @throws RasterFormatException if <code>dataBuffer</code> has more     *         than one bank.     * @throws NullPointerException if <code>dataBuffer</code> is null     */    public static WritableRaster createPackedRaster(DataBuffer dataBuffer,                                                    int w, int h,                                                    int bitsPerPixel,                                                    Point location) {        if (dataBuffer == null) {            throw new NullPointerException("DataBuffer cannot be null");        }        if (location == null) {           location = new Point(0,0);        }        int dataType = dataBuffer.getDataType();        if (dataType != DataBuffer.TYPE_BYTE &&            dataType != DataBuffer.TYPE_USHORT &&            dataType != DataBuffer.TYPE_INT) {            throw new IllegalArgumentException("Unsupported data type " +                                               dataType);        }        if (dataBuffer.getNumBanks() != 1) {            throw new                 RasterFormatException("DataBuffer for packed Rasters"+                                      " must only have 1 bank.");        }                MultiPixelPackedSampleModel mppsm =                new MultiPixelPackedSampleModel(dataType, w, h, bitsPerPixel);        if (dataType == DataBuffer.TYPE_BYTE &&            (bitsPerPixel == 1 || bitsPerPixel == 2 || bitsPerPixel == 4)) {            return new BytePackedRaster(mppsm, dataBuffer, location);        } else {            return new SunWritableRaster(mppsm, dataBuffer, location);        }    }    /**     *  Creates a Raster with the specified SampleModel and DataBuffer.     *  The upper left corner of the Raster is given by the location argument.     *  If location is null, (0, 0) will be used.     *  @param sm the specified <code>SampleModel</code>     *  @param db the specified <code>DataBuffer</code>     *  @param location the upper-left corner of the <code>Raster</code>     *  @return a <code>Raster</code> with the specified      *          <code>SampleModel</code>, <code>DataBuffer</code>, and     *          location.     * @throws RasterFormatException if computing either     *         <code>location.x + sm.getWidth()</code> or     *         <code>location.y + sm.getHeight()</code> results in integer     *         overflow     * @throws RasterFormatException if <code>dataBuffer</code> has more     *         than one bank and the <code>sampleModel</code> is     *         PixelInterleavedSampleModel, SinglePixelPackedSampleModel,     *         or MultiPixelPackedSampleModel.     *  @throws NullPointerException if either SampleModel or DataBuffer is      *          null     */    public static Raster createRaster(SampleModel sm,                                      DataBuffer db,                                      Point location) {        if ((sm == null) || (db == null)) {            throw new NullPointerException("SampleModel and DataBuffer cannot be null");        }                if (location == null) {           location = new Point(0,0);        }        int dataType = sm.getDataType();        if (sm instanceof PixelInterleavedSampleModel) {            switch(dataType) {                case DataBuffer.TYPE_BYTE:                    return new ByteInterleavedRaster(sm, db, location);

⌨️ 快捷键说明

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