本文整理匯總了Java中java.awt.image.PixelInterleavedSampleModel類的典型用法代碼示例。如果您正苦於以下問題:Java PixelInterleavedSampleModel類的具體用法?Java PixelInterleavedSampleModel怎麽用?Java PixelInterleavedSampleModel使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PixelInterleavedSampleModel類屬於java.awt.image包,在下文中一共展示了PixelInterleavedSampleModel類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: makeImage
import java.awt.image.PixelInterleavedSampleModel; //導入依賴的package包/類
BufferedImage makeImage() {
// Generate 8-bit image
//Image img8;
byte[] pixels8;
int color16;
pixels8 = new byte[width*height];
for (int i=0; i<width*height; i++) {
color16 = rgb(pixels32[i]);
pixels8[i] = (byte)hist[color16];
}
SampleModel sampleModel = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, width, height, 1, width, new int[] {0});
DataBufferByte Buffer = new DataBufferByte(pixels8, pixels8.length);
WritableRaster raster = Raster.createWritableRaster(sampleModel, Buffer, null);
return new BufferedImage(cm, raster, false, null);
}
示例2: createFloatBufferedImage
import java.awt.image.PixelInterleavedSampleModel; //導入依賴的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);
}
示例3: main
import java.awt.image.PixelInterleavedSampleModel; //導入依賴的package包/類
public static void main(String[] args) {
byte[][] data = new byte[1][10];
ByteLookupTable lut = new ByteLookupTable(0, data);
RasterOp op = new LookupOp(lut, null);
int[] bandOffsets = {0};
Point location = new Point(0, 0);
DataBuffer db = new DataBufferByte(10 * 10);
SampleModel sm = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
10, 10, 1, 10,
bandOffsets);
Raster src = Raster.createRaster(sm, db, location);
op.filter(src, null); // this used to result in NullPointerException
}
示例4: FilterAsAlphaRed
import java.awt.image.PixelInterleavedSampleModel; //導入依賴的package包/類
/**
* Construct an alpah channel from the given src, according to
* the SVG masking rules.
*
* @param src The image to convert to an alpha channel (mask image)
*/
public FilterAsAlphaRed(CachableRed src) {
super(new Any2LumRed(src),src.getBounds(),
new ComponentColorModel
(ColorSpace.getInstance(ColorSpace.CS_GRAY),
new int [] {8}, false, false,
Transparency.OPAQUE,
DataBuffer.TYPE_BYTE),
new PixelInterleavedSampleModel
(DataBuffer.TYPE_BYTE,
src.getSampleModel().getWidth(),
src.getSampleModel().getHeight(),
1, src.getSampleModel().getWidth(),
new int [] { 0 }),
src.getTileGridXOffset(),
src.getTileGridYOffset(),
null);
props.put(ColorSpaceHintKey.PROPERTY_COLORSPACE,
ColorSpaceHintKey.VALUE_COLORSPACE_ALPHA);
}
示例5: fixSampleModel
import java.awt.image.PixelInterleavedSampleModel; //導入依賴的package包/類
public static SampleModel fixSampleModel(CachableRed src) {
ColorModel cm = src.getColorModel();
SampleModel srcSM = src.getSampleModel();
if (cm.hasAlpha())
return srcSM;
int w = srcSM.getWidth();
int h = srcSM.getHeight();
int b = srcSM.getNumBands()+1;
int [] offsets = new int[b];
for (int i=0; i < b; i++)
offsets[i] = i;
// Really should check DataType range in srcSM...
return new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
w, h, b, w*b, offsets);
}
示例6: createFloatPlanarImage
import java.awt.image.PixelInterleavedSampleModel; //導入依賴的package包/類
public static PlanarImage createFloatPlanarImage(float[] src, int width, int height){
int[] bandOffsets = {0};
SampleModel sampleModel = new PixelInterleavedSampleModel(TYPE_FLOAT, width, height, 1, width, bandOffsets);
ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY);
ColorModel colorModel = new ComponentColorModel(colorSpace, false, false, Transparency.TRANSLUCENT, TYPE_FLOAT);
PlanarImage opImage;
DataBuffer buffer = new DataBufferFloat(width * height);
// Wrap it in a writable raster
WritableRaster raster = Raster.createWritableRaster(sampleModel, buffer, null);
raster.setPixels(0, 0, width, height, src);
// Create an image with this raster
BufferedImage image = new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null);
opImage = PlanarImage.wrapRenderedImage(image);
return opImage;
}
示例7: createSampleModel
import java.awt.image.PixelInterleavedSampleModel; //導入依賴的package包/類
private SampleModel createSampleModel() {
if (samples == 1) {
return new PixelInterleavedSampleModel(dataType, width, height, 1,
width, OFFSETS_0);
}
// samples == 3
if (banded) {
return new BandedSampleModel(dataType, width, height, width,
OFFSETS_0_1_2, OFFSETS_0_0_0);
}
if( (!compressed) && pmi.endsWith("422" ) ) {
return new PartialComponentSampleModel(width, height, 2, 1);
}
if( (!compressed) && pmi.endsWith("420") ) {
return new PartialComponentSampleModel(width,height,2,2);
}
return new PixelInterleavedSampleModel(dataType, width, height, 3,
width * 3, OFFSETS_0_1_2);
}
示例8: convert
import java.awt.image.PixelInterleavedSampleModel; //導入依賴的package包/類
@Override
public SampleModel convert(FieldAccessor fa, Instance instance) throws FieldAccessor.InvalidFieldException {
int width = fa.getInt(instance, "width"); // NOI18N
int height = fa.getInt(instance, "height"); // NOI18N
int dataType = fa.getInt(instance, "dataType"); // NOI18N
int pixelStride = fa.getInt(instance, "pixelStride"); // NOI18N
int scanlineStride = fa.getInt(instance, "scanlineStride"); // NOI18N
int[] bandOffsets = fa.getIntArray(instance, "bandOffsets", false); // NOI18N
return new PixelInterleavedSampleModel(dataType, width, height, pixelStride, scanlineStride, bandOffsets);
}
示例9: main
import java.awt.image.PixelInterleavedSampleModel; //導入依賴的package包/類
public static void main(String[] args) {
Vector<Class<? extends SampleModel>> classes = new Vector<Class<? extends SampleModel>>();
classes.add(ComponentSampleModel.class);
classes.add(MultiPixelPackedSampleModel.class);
classes.add(SinglePixelPackedSampleModel.class);
classes.add(BandedSampleModel.class);
classes.add(PixelInterleavedSampleModel.class);
for (Class<? extends SampleModel> c : classes) {
doTest(c);
}
}
示例10: main
import java.awt.image.PixelInterleavedSampleModel; //導入依賴的package包/類
public static void main(String args[]) {
BufferedImage src
= new BufferedImage(1, 10, BufferedImage.TYPE_INT_ARGB);
// Set src pixel values
Color pelColor = new Color(100, 100, 100, 128);
for (int i = 0; i < 10; i++) {
src.setRGB(0, i, pelColor.getRGB());
}
ColorModel cm = new ComponentColorModel
(ColorSpace.getInstance(ColorSpace.CS_GRAY),
new int [] {8,8}, true,
src.getColorModel().isAlphaPremultiplied(),
Transparency.TRANSLUCENT,
DataBuffer.TYPE_BYTE);
SampleModel sm = new PixelInterleavedSampleModel
(DataBuffer.TYPE_BYTE, 100, 100, 2, 200,
new int [] { 0, 1 });
WritableRaster wr = Raster.createWritableRaster(sm, new Point(0,0));
BufferedImage dst =
new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
dst = dst.getSubimage(0, 0, 1, 10);
ColorConvertOp op = new ColorConvertOp(null);
op.filter(src, dst);
for (int i = 0; i < 10; i++) {
if (((dst.getRGB(0, i) >> 24) & 0xff) != 128) {
throw new RuntimeException(
"Incorrect destination alpha value.");
}
}
}
示例11: createInterleavedSM
import java.awt.image.PixelInterleavedSampleModel; //導入依賴的package包/類
/**
* Create a {@code PixelInterleavedSampleModel} for use in creating
* an {@code ImageTypeSpecifier}. Its dimensions will be 1x1 and
* it will have ascending band offsets as {0, 1, 2, ..., numBands}.
*
* @param dataType The data type (DataBuffer.TYPE_*).
* @param numBands The number of bands.
* @return A {@code PixelInterleavedSampleModel}.
*/
static SampleModel createInterleavedSM(int dataType,
int numBands) {
int[] bandOffsets = new int[numBands];
for(int i = 0; i < numBands; i++) {
bandOffsets[i] = i;
}
return new PixelInterleavedSampleModel(dataType,
1, // width
1, // height
numBands, // pixelStride,
numBands, // scanlineStride
bandOffsets);
}
示例12: for
import java.awt.image.PixelInterleavedSampleModel; //導入依賴的package包/類
private static SampleModel createPixelInterleavedSampleModel
(int dataType, int tileWidth, int tileHeight, int bands) {
int [] bandOffsets = new int[bands];
for (int i=0; i<bands; i++)
bandOffsets[i] = i;
return new PixelInterleavedSampleModel
(dataType, tileWidth, tileHeight, bands,
tileWidth*bands, bandOffsets);
}
示例13: fixSampleModel
import java.awt.image.PixelInterleavedSampleModel; //導入依賴的package包/類
/**
* This function 'fixes' the source's sample model.
* Right now it just selects if it should have one or two bands
* based on if the source had an alpha channel.
*/
protected static SampleModel fixSampleModel(CachableRed src) {
SampleModel sm = src.getSampleModel();
int width = sm.getWidth();
int height = sm.getHeight();
ColorModel cm = src.getColorModel();
if (cm != null) {
if (cm.hasAlpha())
return new PixelInterleavedSampleModel
(DataBuffer.TYPE_BYTE, width, height, 2, 2*width,
new int [] { 0, 1 });
return new PixelInterleavedSampleModel
(DataBuffer.TYPE_BYTE, width, height, 1, width,
new int [] { 0 });
}
else {
// No ColorModel so try to make some intelligent
// decisions based just on the number of bands...
// 1 bands -> lum
// 2 bands -> lum (Band 0) & alpha (Band 1)
// >2 bands -> lum (Band 0) - No color conversion...
if (sm.getNumBands() == 2)
return new PixelInterleavedSampleModel
(DataBuffer.TYPE_BYTE, width, height, 2, 2*width,
new int [] { 0, 1 });
return new PixelInterleavedSampleModel
(DataBuffer.TYPE_BYTE, width, height, 1, width,
new int [] { 0 });
}
}
示例14: createTestImage2
import java.awt.image.PixelInterleavedSampleModel; //導入依賴的package包/類
private static BufferedImage createTestImage2(int nbits, int transfertype) {
final int colorShift = 2;
int SIZE = 256;
BufferedImage image = null;
ColorSpace colorSpace =
ColorSpace.getInstance(ColorSpace.CS_GRAY);
ColorModel colorModel =
new ComponentColorModel(colorSpace,
new int[] {nbits},
false,
false,
Transparency.OPAQUE,
transfertype);
SampleModel sampleModel =
new PixelInterleavedSampleModel(transfertype,
SIZE,
SIZE,
1,
SIZE,
new int[] {0});
image =
new BufferedImage(colorModel,
Raster.createWritableRaster(sampleModel, null),
false, null);
WritableRaster raster = image.getWritableTile(0, 0);
int[] samples = raster.getSamples(0, 0, SIZE, SIZE, 0, (int[])null);
int off = 0;
int[] row = new int[SIZE];
for(int i = 0; i < SIZE; i++) {
Arrays.fill(row, i << colorShift);
System.arraycopy(row, 0, samples, off, SIZE);
off += SIZE;
}
raster.setSamples(0, 0, SIZE, SIZE, 0, samples);
return image;
}
示例15: createTestImage3
import java.awt.image.PixelInterleavedSampleModel; //導入依賴的package包/類
private static BufferedImage createTestImage3(int nbits, int transfertype) {
final int colorShift = 2;
int SIZE = 256;
BufferedImage image = null;
ColorSpace colorSpace =
ColorSpace.getInstance(ColorSpace.CS_sRGB);
ColorModel colorModel =
new IndexColorModel(nbits,
4,
new byte[] { (byte)255, 0, 0, (byte)255},
new byte[] { 0, (byte)255, 0, (byte)255},
new byte[] { 0, 0, (byte)255, (byte)255});
SampleModel sampleModel =
new PixelInterleavedSampleModel(transfertype,
SIZE,
SIZE,
1,
SIZE,
new int[] {0});
image =
new BufferedImage(colorModel,
Raster.createWritableRaster(sampleModel, null),
false, null);
Graphics2D g = image.createGraphics();
g.setColor(Color.white);
g.fillRect(0,0, SIZE, SIZE);
g.setColor(Color.red);
g.fillOval(10, 10, SIZE -20, SIZE-20);
return image;
}