当前位置: 首页>>代码示例>>Java>>正文


Java SampleModel类代码示例

本文整理汇总了Java中java.awt.image.SampleModel的典型用法代码示例。如果您正苦于以下问题:Java SampleModel类的具体用法?Java SampleModel怎么用?Java SampleModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SampleModel类属于java.awt.image包,在下文中一共展示了SampleModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getElementSize

import java.awt.image.SampleModel; //导入依赖的package包/类
public static int getElementSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof MultiPixelPackedSampleModel) {
        MultiPixelPackedSampleModel mppsm =
            (MultiPixelPackedSampleModel)sm;
        return mppsm.getSampleSize(0) * mppsm.getNumBands();
    } else if (sm instanceof ComponentSampleModel) {
        return sm.getNumBands() * elementSize;
    } else if (sm instanceof SinglePixelPackedSampleModel) {
        return elementSize;
    }

    return elementSize * sm.getNumBands();

}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:ImageUtil.java

示例2: areSampleSizesEqual

import java.awt.image.SampleModel; //导入依赖的package包/类
/**
 * Returns whether all samples have the same number of bits.
 */
private static boolean areSampleSizesEqual(SampleModel sm) {
    boolean allSameSize = true;
    int[] sampleSize = sm.getSampleSize();
    int sampleSize0 = sampleSize[0];
    int numBands = sampleSize.length;

    for(int i = 1; i < numBands; i++) {
        if(sampleSize[i] != sampleSize0) {
            allSameSize = false;
            break;
        }
    }

    return allSameSize;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:TIFFDecompressor.java

示例3: getBandSize

import java.awt.image.SampleModel; //导入依赖的package包/类
public static long getBandSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof ComponentSampleModel) {
        ComponentSampleModel csm = (ComponentSampleModel)sm;
        int pixelStride = csm.getPixelStride();
        int scanlineStride = csm.getScanlineStride();
        long size = Math.min(pixelStride, scanlineStride);

        if (pixelStride > 0)
            size += pixelStride * (sm.getWidth() - 1);
        if (scanlineStride > 0)
            size += scanlineStride * (sm.getHeight() - 1);
        return size * ((elementSize + 7) / 8);
    } else
        return getTileSize(sm);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:ImageUtil.java

示例4: canEncodeImage

import java.awt.image.SampleModel; //导入依赖的package包/类
public boolean canEncodeImage(ImageTypeSpecifier type) {
    if (type == null) {
        throw new IllegalArgumentException("type == null!");
    }

    SampleModel sm = type.getSampleModel();
    ColorModel cm = type.getColorModel();

    boolean canEncode = sm.getNumBands() == 1 &&
        sm.getSampleSize(0) <= 8 &&
        sm.getWidth() <= 65535 &&
        sm.getHeight() <= 65535 &&
        (cm == null || cm.getComponentSize()[0] <= 8);

    if (canEncode) {
        return true;
    } else {
        return PaletteBuilder.canCreatePalette(type);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:GIFImageWriterSpi.java

示例5: canEncodeImage

import java.awt.image.SampleModel; //导入依赖的package包/类
public boolean canEncodeImage(ImageTypeSpecifier type) {
    SampleModel sampleModel = type.getSampleModel();

    // Find the maximum bit depth across all channels
    int[] sampleSize = sampleModel.getSampleSize();
    int bitDepth = sampleSize[0];
    for (int i = 1; i < sampleSize.length; i++) {
        if (sampleSize[i] > bitDepth) {
            bitDepth = sampleSize[i];
        }
    }

    // 4450894: Ensure bitDepth is between 1 and 8
    if (bitDepth < 1 || bitDepth > 8) {
        return false;
    }

    return true;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:JPEGImageWriterSpi.java

示例6: main

import java.awt.image.SampleModel; //导入依赖的package包/类
public static void main(String[] args) {
    SampleModel sm = new ComponentSampleModel(dataType, width, height, 4, width * 4, new int[] { 0, 1, 2, 3 } );

    DataBuffer db = sm.createDataBuffer();
    Object o = null;

    boolean testPassed = false;
    try {
        o = sm.getDataElements(Integer.MAX_VALUE, 0, 1, 1, o, db);
    } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println(e.getMessage());
        testPassed = true;
    }

    if (!testPassed) {
        throw new RuntimeException("Excpected excprion was not thrown.");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:GetDataElementsTest.java

示例7: canEncodeImage

import java.awt.image.SampleModel; //导入依赖的package包/类
public boolean canEncodeImage(ImageTypeSpecifier type) {
    int dataType= type.getSampleModel().getDataType();
    if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_INT)
        return false;

    SampleModel sm = type.getSampleModel();
    int numBands = sm.getNumBands();
    if (!(numBands == 1 || numBands == 3))
        return false;

    if (numBands == 1 && dataType != DataBuffer.TYPE_BYTE)
        return false;

    if (dataType > DataBuffer.TYPE_BYTE &&
          !(sm instanceof SinglePixelPackedSampleModel))
        return false;

    return true;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:BMPImageWriterSpi.java

示例8: createFloatBufferedImage

import java.awt.image.SampleModel; //导入依赖的package包/类
BufferedImage createFloatBufferedImage(int w, int h, int bands) {
    // Define dimensions and layout of the image
    //int bands = 4; // 4 bands for ARGB, 3 for RGB etc
    int[] bandOffsets = {0, 1, 2, 3}; // length == bands, 0 == R, 1 == G, 2 == B and 3 == A

    // Create a TYPE_FLOAT sample model (specifying how the pixels are stored)
    SampleModel sampleModel = new PixelInterleavedSampleModel(DataBuffer.TYPE_FLOAT, w, h, bands, w  * bands, bandOffsets);
    // ...and data buffer (where the pixels are stored)
    DataBuffer buffer = new DataBufferFloat(w * h * bands);

    // Wrap it in a writable raster
    WritableRaster raster = Raster.createWritableRaster(sampleModel, buffer, null);

    // Create a color model compatible with this sample model/raster (TYPE_FLOAT)
    // Note that the number of bands must equal the number of color components in the 
    // color space (3 for RGB) + 1 extra band if the color model contains alpha 
    ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorModel colorModel = new ComponentColorModel(colorSpace, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_FLOAT);

    // And finally create an image with this raster
    return new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null);
}
 
开发者ID:iapafoto,项目名称:DicomViewer,代码行数:23,代码来源:OpenCLWithJOCL.java

示例9: getDefaultEncodeParam

import java.awt.image.SampleModel; //导入依赖的package包/类
/**
 * Returns an instance of <code>PNGEncodeParam.Palette</code>,
 * <code>PNGEncodeParam.Gray</code>, or
 * <code>PNGEncodeParam.RGB</code> appropriate for encoding
 * the given image.
 *
 * <p> If the image has an <code>IndexColorModel</code>, an
 * instance of <code>PNGEncodeParam.Palette</code> is returned.
 * Otherwise, if the image has 1 or 2 bands an instance of
 * <code>PNGEncodeParam.Gray</code> is returned.  In all other
 * cases an instance of <code>PNGEncodeParam.RGB</code> is
 * returned.
 *
 * <p> Note that this method does not provide any guarantee that
 * the given image will be successfully encoded by the PNG
 * encoder, as it only performs a very superficial analysis of
 * the image structure.
 */
public static mxPngEncodeParam getDefaultEncodeParam(RenderedImage im)
{
	ColorModel colorModel = im.getColorModel();
	if (colorModel instanceof IndexColorModel)
	{
		return new mxPngEncodeParam.Palette();
	}

	SampleModel sampleModel = im.getSampleModel();
	int numBands = sampleModel.getNumBands();

	if (numBands == 1 || numBands == 2)
	{
		return new mxPngEncodeParam.Gray();
	}
	else
	{
		return new mxPngEncodeParam.RGB();
	}
}
 
开发者ID:GDSRS,项目名称:TrabalhoFinalEDA2,代码行数:39,代码来源:mxPngEncodeParam.java

示例10: ImageTypeSpecifier

import java.awt.image.SampleModel; //导入依赖的package包/类
/**
 * Constructs an {@code ImageTypeSpecifier} directly
 * from a {@code ColorModel} and a {@code SampleModel}.
 * It is the caller's responsibility to supply compatible
 * parameters.
 *
 * @param colorModel a {@code ColorModel}.
 * @param sampleModel a {@code SampleModel}.
 *
 * @exception IllegalArgumentException if either parameter is
 * {@code null}.
 * @exception IllegalArgumentException if {@code sampleModel}
 * is not compatible with {@code colorModel}.
 */
public ImageTypeSpecifier(ColorModel colorModel, SampleModel sampleModel) {
    if (colorModel == null) {
        throw new IllegalArgumentException("colorModel == null!");
    }
    if (sampleModel == null) {
        throw new IllegalArgumentException("sampleModel == null!");
    }
    if (!colorModel.isCompatibleSampleModel(sampleModel)) {
        throw new IllegalArgumentException
            ("sampleModel is incompatible with colorModel!");
    }
    this.colorModel = colorModel;
    this.sampleModel = sampleModel;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:ImageTypeSpecifier.java

示例11: IntegerComponentRaster

import java.awt.image.SampleModel; //导入依赖的package包/类
/**
 *  Constructs a IntegerComponentRaster with the given SampleModel.
 *  The Raster's upper left corner is origin and it is the same
 *  size as the SampleModel.  A DataBuffer large enough to describe the
 *  Raster is automatically created.  SampleModel must be of type
 *  SinglePixelPackedSampleModel.
 *  @param sampleModel     The SampleModel that specifies the layout.
 *  @param origin          The Point that specified the origin.
 */
public IntegerComponentRaster(SampleModel sampleModel,
                                 Point origin) {
    this(sampleModel,
         sampleModel.createDataBuffer(),
         new Rectangle(origin.x,
                       origin.y,
                       sampleModel.getWidth(),
                       sampleModel.getHeight()),
         origin,
         null);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:IntegerComponentRaster.java

示例12: ByteComponentRaster

import java.awt.image.SampleModel; //导入依赖的package包/类
/**
 * Constructs a ByteComponentRaster with the given SampleModel
 * and DataBuffer.  The Raster's upper left corner is origin and
 * it is the same size as the SampleModel.  The DataBuffer is not
 * initialized and must be a DataBufferByte compatible with SampleModel.
 * SampleModel must be of type SinglePixelPackedSampleModel
 * or ComponentSampleModel.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferShort that contains the image data.
 * @param origin          The Point that specifies the origin.
 */
public ByteComponentRaster(SampleModel sampleModel,
                              DataBuffer dataBuffer,
                              Point origin) {
    this(sampleModel,
         dataBuffer,
         new Rectangle(origin.x,
                       origin.y,
                       sampleModel.getWidth(),
                       sampleModel.getHeight()),
         origin,
         null);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:ByteComponentRaster.java

示例13: getThumbnail

import java.awt.image.SampleModel; //导入依赖的package包/类
BufferedImage getThumbnail(ImageInputStream iis,
                           JPEGImageReader reader)
    throws IOException {
    iis.mark();
    iis.seek(streamPos);
    // read the palette
    byte [] palette = new byte [PALETTE_SIZE];
    float palettePart = ((float) PALETTE_SIZE) / getLength();
    readByteBuffer(iis,
                   palette,
                   reader,
                   palettePart,
                   0.0F);
    DataBufferByte buffer = new DataBufferByte(thumbWidth*thumbHeight);
    readByteBuffer(iis,
                   buffer.getData(),
                   reader,
                   1.0F-palettePart,
                   palettePart);
    iis.read();
    iis.reset();

    IndexColorModel cm = new IndexColorModel(8,
                                             256,
                                             palette,
                                             0,
                                             false);
    SampleModel sm = cm.createCompatibleSampleModel(thumbWidth,
                                                    thumbHeight);
    WritableRaster raster =
        Raster.createWritableRaster(sm, buffer, null);
    return new BufferedImage(cm,
                             raster,
                             false,
                             null);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:JFIFMarkerSegment.java

示例14: main

import java.awt.image.SampleModel; //导入依赖的package包/类
public static void main(String[] args) throws IIOInvalidTreeException {

        // getting the writer for the png format
        Iterator iter = ImageIO.getImageWritersByFormatName("png");
        ImageWriter writer = (ImageWriter) iter.next();

        // creating a color model
        ColorModel colorModel = ColorModel.getRGBdefault();

        // creating a sample model
        SampleModel sampleModel = colorModel.createCompatibleSampleModel(640, 480);

        // creating a default metadata object
        IIOMetadata metaData = writer.getDefaultImageMetadata(new ImageTypeSpecifier(colorModel, sampleModel), null);
        String formatName = metaData.getNativeMetadataFormatName();

        // first call
        Node metaDataNode = metaData.getAsTree(formatName);
        try {
            metaData.setFromTree(formatName, metaDataNode);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        // second call (bitdepht is already set to an invalid value)
        metaDataNode = metaData.getAsTree(formatName);

        metaData.setFromTree(formatName, metaDataNode);

    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:PngDitDepthTest.java

示例15: ByteBandedRaster

import java.awt.image.SampleModel; //导入依赖的package包/类
/**
 *  Constructs a ByteBandedRaster with the given sampleModel. The
 *  Raster's upper left corner is origin and it is the same
 *  size as the SampleModel.  A dataBuffer large
 *  enough to describe the Raster is automatically created. SampleModel
 *  must be of type BandedSampleModel.
 *  @param sampleModel     The SampleModel that specifies the layout.
 *  @param origin          The Point that specifies the origin.
 */
public ByteBandedRaster(SampleModel sampleModel,
                           Point origin) {
    this(sampleModel,
         sampleModel.createDataBuffer(),
         new Rectangle(origin.x,
                       origin.y,
                       sampleModel.getWidth(),
                       sampleModel.getHeight()),
         origin,
         null);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:ByteBandedRaster.java


注:本文中的java.awt.image.SampleModel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。