本文整理汇总了Java中java.awt.image.DataBuffer类的典型用法代码示例。如果您正苦于以下问题:Java DataBuffer类的具体用法?Java DataBuffer怎么用?Java DataBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataBuffer类属于java.awt.image包,在下文中一共展示了DataBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSizeEquality
import java.awt.image.DataBuffer; //导入依赖的package包/类
private static void testSizeEquality() {
// test with different size for cmap.
IndexColorModel model1 = new IndexColorModel(8, 4,
new int[] {1, 2, 3, 4},
0, true, -1, DataBuffer.TYPE_BYTE);
IndexColorModel model2 = new IndexColorModel(8, 3,
new int[] {1, 2, 3},
0, true, -1, DataBuffer.TYPE_BYTE);
if (model1.equals(model2)) {
throw new RuntimeException("equals() method is determining"
+ " Map size equality improperly");
}
if (model2.equals(model1)) {
throw new RuntimeException("equals() method is determining"
+ " Map size equality improperly");
}
}
示例2: makeImage
import java.awt.image.DataBuffer; //导入依赖的package包/类
public Image makeImage(TestEnvironment env, int w, int h) {
BufferedImage img = new BufferedImage(w, h, type);
if (unmanaged) {
DataBuffer db = img.getRaster().getDataBuffer();
if (db instanceof DataBufferInt) {
((DataBufferInt)db).getData();
} else if (db instanceof DataBufferShort) {
((DataBufferShort)db).getData();
} else if (db instanceof DataBufferByte) {
((DataBufferByte)db).getData();
} else {
try {
img.setAccelerationPriority(0.0f);
} catch (Throwable e) {}
}
}
return img;
}
示例3: makeUnmanagedBI
import java.awt.image.DataBuffer; //导入依赖的package包/类
private static BufferedImage makeUnmanagedBI(GraphicsConfiguration gc,
int type) {
BufferedImage img = gc.createCompatibleImage(SIZE, SIZE, type);
Graphics2D g2d = img.createGraphics();
g2d.setColor(RGB);
g2d.fillRect(0, 0, SIZE, SIZE);
g2d.dispose();
final DataBuffer db = img.getRaster().getDataBuffer();
if (db instanceof DataBufferInt) {
((DataBufferInt) db).getData();
} else if (db instanceof DataBufferShort) {
((DataBufferShort) db).getData();
} else if (db instanceof DataBufferByte) {
((DataBufferByte) db).getData();
} else {
try {
img.setAccelerationPriority(0.0f);
} catch (final Throwable ignored) {
}
}
return img;
}
示例4: getDTName
import java.awt.image.DataBuffer; //导入依赖的package包/类
static String getDTName(int dType) {
switch(dType) {
case DataBuffer.TYPE_BYTE:
return "TYPE_BYTE";
case DataBuffer.TYPE_DOUBLE:
return "TYPE_DOUBLE";
case DataBuffer.TYPE_FLOAT:
return "TYPE_FLOAT";
case DataBuffer.TYPE_INT:
return "TYPE_INT";
case DataBuffer.TYPE_SHORT:
return "TYPE_SHORT";
case DataBuffer.TYPE_USHORT:
return "TYPE_USHORT";
case DataBuffer.TYPE_UNDEFINED:
return "TYPE_UNDEFINED";
}
return "UNKNOWN";
}
示例5: getColorModel
import java.awt.image.DataBuffer; //导入依赖的package包/类
@Override
public ColorModel getColorModel(int transparency) {
switch (transparency) {
case Transparency.OPAQUE:
// REMIND: once the ColorModel spec is changed, this should be
// an opaque premultiplied DCM...
return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
case Transparency.BITMASK:
return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
case Transparency.TRANSLUCENT:
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
return new DirectColorModel(cs, 32,
0xff0000, 0xff00, 0xff, 0xff000000,
true, DataBuffer.TYPE_INT);
default:
return null;
}
}
示例6: main
import java.awt.image.DataBuffer; //导入依赖的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: getBandSize
import java.awt.image.DataBuffer; //导入依赖的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);
}
示例8: makeUnmanagedBI
import java.awt.image.DataBuffer; //导入依赖的package包/类
private static BufferedImage makeUnmanagedBI() {
final BufferedImage bi = new BufferedImage(500, 200, TYPE_INT_ARGB);
final DataBuffer db = bi.getRaster().getDataBuffer();
if (db instanceof DataBufferInt) {
((DataBufferInt) db).getData();
} else if (db instanceof DataBufferShort) {
((DataBufferShort) db).getData();
} else if (db instanceof DataBufferByte) {
((DataBufferByte) db).getData();
} else {
try {
bi.setAccelerationPriority(0.0f);
} catch (final Throwable ignored) {
}
}
return bi;
}
示例9: getElementSize
import java.awt.image.DataBuffer; //导入依赖的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();
}
示例10: testValidPixelsEquality
import java.awt.image.DataBuffer; //导入依赖的package包/类
private static void testValidPixelsEquality() {
// test with different valid pixels.
/*
* In setRGBs() function of IndexColorModel we override
* transparent_index value to map to pixel value if alpha is 0x00
* so we should have atleast minimum alpha value to verify
* equality of validBits thats why we have color value as
* 16777216(2 ^ 24).
*/
int color = 16777216;
IndexColorModel model1 = new IndexColorModel(8, 3, new int[] {color,
color, color}, 0, DataBuffer.TYPE_BYTE, new BigInteger("1"));
IndexColorModel model2 = new IndexColorModel(8, 3, new int[] {color,
color, color}, 0, DataBuffer.TYPE_BYTE, new BigInteger("2"));
if (model1.equals(model2)) {
throw new RuntimeException("equals() method is determining"
+ " Valid pixels equality improperly");
}
if (model2.equals(model1)) {
throw new RuntimeException("equals() method is determining"
+ " Valid pixels equality improperly");
}
}
示例11: createBuffer
import java.awt.image.DataBuffer; //导入依赖的package包/类
/**
* Create a data buffer of a particular type.
*
* @param dataType the desired data type of the buffer.
* @param size the size of the data buffer bank
* @param numBanks the number of banks the buffer should have
*/
public static DataBuffer createBuffer(int dataType, int size, int numBanks)
{
switch (dataType)
{
case DataBuffer.TYPE_BYTE:
return new DataBufferByte(size, numBanks);
case DataBuffer.TYPE_SHORT:
return new DataBufferShort(size, numBanks);
case DataBuffer.TYPE_USHORT:
return new DataBufferUShort(size, numBanks);
case DataBuffer.TYPE_INT:
return new DataBufferInt(size, numBanks);
case DataBuffer.TYPE_FLOAT:
return new DataBufferFloat(size, numBanks);
case DataBuffer.TYPE_DOUBLE:
return new DataBufferDouble(size, numBanks);
default:
throw new UnsupportedOperationException();
}
}
示例12: testConstructor7
import java.awt.image.DataBuffer; //导入依赖的package包/类
private static void testConstructor7() {
/*
* verify equality with constructor
* IndexColorModel(int bits, int size, int[] cmap, int start,
* int transferType, BigInteger validBits)
*/
/*
* In setRGBs() function of IndexColorModel we override
* transparent_index value to map to pixel value if alpha is 0x00
* so we should have atleast minimum alpha value to keep
* both model1 and model2 same.
*/
int color = 16777216;
IndexColorModel model1 = new IndexColorModel(8, 3, new int[] {color,
color, color}, 0, DataBuffer.TYPE_BYTE, new BigInteger("1"));
IndexColorModel model2 = new IndexColorModel(8, 3, new int[] {color,
color, color}, 0, DataBuffer.TYPE_BYTE, new BigInteger("1"));
verifyEquals(model1, model2);
}
示例13: allocateRgbImage
import java.awt.image.DataBuffer; //导入依赖的package包/类
/**
* @param windowWidth
* @param windowHeight
* @param pBuffer
* @param windowSize
* @param backgroundTransparent
* @return an Image
*/
static Object allocateRgbImage(int windowWidth, int windowHeight,
int[] pBuffer, int windowSize,
boolean backgroundTransparent) {
//backgroundTransparent not working with antialiasDisplay. I have no idea why. BH 9/24/08
/* DEAD CODE if (false && backgroundTransparent)
return new BufferedImage(
rgbColorModelT,
Raster.createWritableRaster(
new SinglePixelPackedSampleModel(
DataBuffer.TYPE_INT,
windowWidth,
windowHeight,
sampleModelBitMasksT),
new DataBufferInt(pBuffer, windowSize),
null),
false,
null);
*/
return new BufferedImage(rgbColorModel, Raster.createWritableRaster(
new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, windowWidth,
windowHeight, sampleModelBitMasks), new DataBufferInt(pBuffer,
windowSize), null), false, null);
}
示例14: CSampleModel
import java.awt.image.DataBuffer; //导入依赖的package包/类
/** Creates a new instance of CSampleModel */
public CSampleModel(int width, int height) {
super (DataBuffer.TYPE_INT, width, height, MASKS);
this.buf = buf;
this.width = width;
this.height = height;
}
示例15: convert
import java.awt.image.DataBuffer; //导入依赖的package包/类
@Override
public DataBuffer convert(FieldAccessor fa, Instance instance) throws FieldAccessor.InvalidFieldException {
int size = fa.getInt(instance, "size"); // NOI18N
int[] offsets = fa.getIntArray(instance, "offsets", false); // NOI18N
//int[] data = fa.getIntArray(instance, "data", false); // NOI18N
int[][] bankdata = fa.getIntArray2(instance, "bankdata", false); // NOI18N
return new DataBufferInt(bankdata, size, offsets);
}