本文整理汇总了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();
}
示例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;
}
示例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);
}
示例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);
}
}
示例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;
}
示例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.");
}
}
示例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;
}
示例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);
}
示例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();
}
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}