本文整理汇总了Java中java.awt.image.ComponentSampleModel类的典型用法代码示例。如果您正苦于以下问题:Java ComponentSampleModel类的具体用法?Java ComponentSampleModel怎么用?Java ComponentSampleModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ComponentSampleModel类属于java.awt.image包,在下文中一共展示了ComponentSampleModel类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getElementSize
import java.awt.image.ComponentSampleModel; //导入依赖的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: getBandSize
import java.awt.image.ComponentSampleModel; //导入依赖的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);
}
示例3: main
import java.awt.image.ComponentSampleModel; //导入依赖的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.");
}
}
示例4: getSnapshot
import java.awt.image.ComponentSampleModel; //导入依赖的package包/类
@Override
public BufferedImage getSnapshot()
{
// TODO: Support non-24-bit resolutions.
int w = pixmap.width;
int h = pixmap.height;
ZPixmap zpixmap = (ZPixmap) pixmap.image(0, 0, w, h, 0xffffffff,
Image.Format.ZPIXMAP);
DataBuffer buffer = new ZPixmapDataBuffer(zpixmap);
SampleModel sm = new ComponentSampleModel(DataBuffer.TYPE_BYTE, w, h, 4,
w * 4,
new int[]{0, 1, 2, 3 });
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
ColorModel cm = new ComponentColorModel(cs, true, false,
Transparency.OPAQUE,
DataBuffer.TYPE_BYTE);
WritableRaster raster = Raster.createWritableRaster(sm, buffer,
new Point(0, 0));
return new BufferedImage(cm, raster, false, null);
}
示例5: ceateImageContent
import java.awt.image.ComponentSampleModel; //导入依赖的package包/类
private TiledImage ceateImageContent(float[] data, int columns, int rows) {
SampleModel sm = new ComponentSampleModel(DataBuffer.TYPE_DOUBLE,
TILE_SIZE, TILE_SIZE, 1, TILE_SIZE, new int[]{0});
ColorModel cm = TiledImage.createColorModel(sm);
TiledImage img = new TiledImage(0, 0, columns, rows, 0, 0, sm, cm);
int i = 0;
int halfColumns = (int) ((double) columns / 2.0);
for (int y = 0; y < rows; y++) {
for (int x = 0; x < columns; x++) {
if (x >= halfColumns) {
img.setSample(x - halfColumns, y, 0, data[i]);
} else {
img.setSample(x + halfColumns, y, 0, data[i]);
}
i++;
}
}
return img;
}
示例6: RectIterCSM
import java.awt.image.ComponentSampleModel; //导入依赖的package包/类
public RectIterCSM(RenderedImage im, Rectangle bounds) {
super(im, bounds);
ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
this.scanlineStride = csm.getScanlineStride();
this.pixelStride = csm.getPixelStride();
this.bankIndices = csm.getBankIndices();
int[] bo = csm.getBandOffsets();
this.bandOffsets = new int[numBands + 1];
for (int i = 0; i < numBands; i++) {
bandOffsets[i] = bo[i];
}
bandOffsets[numBands] = 0;
this.DBOffsets = new int[numBands];
this.offset = (y - sampleModelTranslateY)*scanlineStride +
(x - sampleModelTranslateX)*pixelStride;
this.bandOffset = bandOffsets[0];
}
示例7: getBufferSizeCSM
import java.awt.image.ComponentSampleModel; //导入依赖的package包/类
private static long getBufferSizeCSM(ComponentSampleModel csm) {
int[] bandOffsets = csm.getBandOffsets();
int maxBandOff=bandOffsets[0];
for (int i=1; i<bandOffsets.length; i++)
maxBandOff = Math.max(maxBandOff,bandOffsets[i]);
long size = 0;
if (maxBandOff >= 0)
size += maxBandOff+1;
int pixelStride = csm.getPixelStride();
if (pixelStride > 0)
size += pixelStride * (csm.getWidth()-1);
int scanlineStride = csm.getScanlineStride();
if (scanlineStride > 0)
size += scanlineStride*(csm.getHeight()-1);
return size;
}
示例8: getImage
import java.awt.image.ComponentSampleModel; //导入依赖的package包/类
public static BufferedImage getImage(UVCController.UVCFrame frame) {
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
// raster in "BGR" order like OpenCV..
int[] offsets = new int[]{2, 1, 0};
ColorModel cm = new ComponentColorModel(cs, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
ComponentSampleModel csm = new ComponentSampleModel(DataBuffer.TYPE_BYTE, frame.width(), frame.height(), 3, frame.width() * 3, offsets);
WritableRaster wr = Raster.createWritableRaster(csm, null);
BufferedImage bImage = new BufferedImage(cm, wr, false, null);
DataBufferByte out = (DataBufferByte) bImage.getRaster().getDataBuffer();
ByteBuffer buff = frame.data().capacity(frame.data_bytes()).asByteBuffer();
copyByteBuffer(buff, frame.width() * 3, ByteBuffer.wrap(out.getData()), frame.width() * 3);
return bImage;
}
示例9: copyGlyphToBufferedImageGray
import java.awt.image.ComponentSampleModel; //导入依赖的package包/类
static boolean copyGlyphToBufferedImageGray(FT2Library.FT_Bitmap bitmap, BufferedImage img, int x, int y) {
if (x + bitmap.width > img.getWidth()) {
return false;
}
if (y + bitmap.rows > img.getHeight()) {
return false;
}
final DataBufferByte dataBuffer = (DataBufferByte) img.getRaster().getDataBuffer();
final byte[] data = dataBuffer.getData();
final int stride = ((ComponentSampleModel) img.getSampleModel()).getScanlineStride();
ByteBuffer bb = bitmap.buffer.getByteBuffer(0, Math.abs(bitmap.pitch) * bitmap.rows);
int bbOff = (bitmap.pitch < 0) ? (-bitmap.pitch * (bitmap.rows - 1)) : 0;
int dataOff = dataBuffer.getOffset() + y * stride + x;
for (int r = 0; r < bitmap.rows; r++, bbOff += bitmap.pitch, dataOff += stride) {
for (int c = 0; c < bitmap.width; c++) {
data[dataOff + c] = (byte) (bb.get(bbOff + c) ^ 0xff);
}
}
return true;
}
示例10: test_from_BuffImg_to_FloatDataBuffer
import java.awt.image.ComponentSampleModel; //导入依赖的package包/类
public final void test_from_BuffImg_to_FloatDataBuffer(){
src = createImage(BufferedImage.TYPE_INT_RGB);
DataBufferFloat dbf = new DataBufferFloat(w * h * 3);
int offsets[] = new int[]{0,1,2};
ComponentSampleModel csm = new ComponentSampleModel(DataBuffer.TYPE_FLOAT,
w, h, 3, 3 * w, offsets);
WritableRaster wr = new OrdinaryWritableRaster(csm, dbf, new Point(0, 0));
ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false, Transparency.OPAQUE, DataBuffer.TYPE_FLOAT);
BufferedImage dst = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
Graphics2D g2d = dst.createGraphics();
g2d.drawImage(src, 0, 0, null);
for(int y = 0; y < h; y++){
for(int x = 0; x < w; x++){
assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
}
}
}