本文整理了Java中java.awt.image.Raster.createInterleavedRaster
方法的一些代码示例,展示了Raster.createInterleavedRaster
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Raster.createInterleavedRaster
方法的具体详情如下:
包路径:java.awt.image.Raster
类名称:Raster
方法名:createInterleavedRaster
暂无
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
Transparency.BITMASK,
DataBuffer.TYPE_BYTE);
WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
width, height,
width*2, 2,
代码示例来源:origin: nutzam/nutz
raster = Raster.createInterleavedRaster(new DataBufferByte(rgb, rgb.length),
w,
h,
代码示例来源:origin: haraldk/TwelveMonkeys
BufferedImage imageFromRawData(int width, int height, int scanLine, byte[] data) {
DataBuffer buffer = new DataBufferByte(data, data.length);
WritableRaster raster = Raster.createInterleavedRaster(
buffer, width, height,
scanLine, 3,
new int[]{0, 1, 2},
null
);
ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
return new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null);
}
代码示例来源:origin: haraldk/TwelveMonkeys
static protected BufferedImage readRawThumbnail(final byte[] thumbnail, final int size, final int offset, int w, int h) {
DataBufferByte buffer = new DataBufferByte(thumbnail, size, offset);
WritableRaster raster;
ColorModel cm;
if (thumbnail.length == w * h) {
raster = Raster.createInterleavedRaster(buffer, w, h, w, 1, new int[] {0}, null);
cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY), false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
}
else {
raster = Raster.createInterleavedRaster(buffer, w, h, w * 3, 3, new int[] {0, 1, 2}, null);
cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
}
return new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null);
}
代码示例来源:origin: apache/pdfbox
private BufferedImage create2ByteGrayAlphaImage(int width, int height)
{
/**
* gray + alpha
*/
int[] bandOffsets = new int[] {1, 0};
int bands = bandOffsets.length;
/**
* Color Model usesd for raw GRAY + ALPHA
*/
final ColorModel CM_GRAY_ALPHA
= new ComponentColorModel(
ColorSpace.getInstance(ColorSpace.CS_GRAY),
true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
// Init data buffer of type byte
DataBuffer buffer = new DataBufferByte(width * height * bands);
// Wrap the data buffer in a raster
WritableRaster raster =
Raster.createInterleavedRaster(buffer, width, height,
width * bands, bands, bandOffsets, new Point(0, 0));
// Create a custom BufferedImage with the raster and a suitable color model
return new BufferedImage(CM_GRAY_ALPHA, raster, false, null);
}
代码示例来源:origin: geotools/geotools
/**
* create a buffered image from a set of color triplets
*
* @param data
* @param width
* @param height
* @return
*/
public static BufferedImage ByteBufferImage(byte[] data, int width, int height) {
int[] bandoffsets = {0, 1, 2, 3};
DataBufferByte dbb = new DataBufferByte(data, data.length);
WritableRaster wr =
Raster.createInterleavedRaster(dbb, width, height, width * 4, 4, bandoffsets, null);
int[] bitfield = {8, 8, 8, 8};
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
ColorModel cm =
new ComponentColorModel(
cs, bitfield, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
return new BufferedImage(cm, wr, false, null);
}
代码示例来源:origin: haraldk/TwelveMonkeys
/**
* Converts a gray {@code MagickImage} to a {@code BufferedImage}, of
* type {@code TYPE_USHORT_GRAY} or {@code TYPE_BYTE_GRAY}.
*
* @param pImage the original {@code MagickImage}
* @param pAlpha keep alpha channel
* @return a new {@code BufferedImage}
*
* @throws MagickException if an exception occurs during conversion
*
* @see BufferedImage
*/
private static BufferedImage grayToBuffered(MagickImage pImage, boolean pAlpha) throws MagickException {
Dimension size = pImage.getDimension();
int length = size.width * size.height;
int bands = pAlpha ? 2 : 1;
byte[] pixels = new byte[length * bands];
// TODO: Make a fix for 16 bit TYPE_USHORT_GRAY?!
// Note: The ordering AI or I corresponds to BufferedImage
// TYPE_CUSTOM and TYPE_BYTE_GRAY respectively
pImage.dispatchImage(0, 0, size.width, size.height, pAlpha ? "AI" : "I", pixels);
// Init databuffer with array, to avoid allocation of empty array
DataBuffer buffer = new DataBufferByte(pixels, pixels.length);
int[] bandOffsets = pAlpha ? new int[] {1, 0} : new int[] {0};
WritableRaster raster =
Raster.createInterleavedRaster(buffer, size.width, size.height,
size.width * bands, bands, bandOffsets, LOCATION_UPPER_LEFT);
return new BufferedImage(pAlpha ? CM_GRAY_ALPHA : CM_GRAY_OPAQUE, raster, pAlpha, null);
}
代码示例来源:origin: haraldk/TwelveMonkeys
Raster.createInterleavedRaster(buffer, size.width, size.height,
size.width * bands, bands, bandOffsets, LOCATION_UPPER_LEFT);
代码示例来源:origin: haraldk/TwelveMonkeys
void writeUncompressed(boolean isTopDown, BufferedImage img, int height, int width) throws IOException {
// TODO: Fix
if (img.getType() != BufferedImage.TYPE_4BYTE_ABGR) {
throw new IIOException("Blows!");
}
// Support
// - TODO: IndexColorModel (ucompressed, RLE4, RLE8 or BI_PNG)
// - TODO: ComponentColorModel (1 channel gray, 3 channel BGR and 4 channel BGRA, uncompressed and RLE8? BI_BITFIELDS? BI_PNG? BI_JPEG?)
// - TODO: Packed/DirectColorModel (16 and 32 bit, BI_BITFIELDS, BI_PNG? BI_JPEG?)
Raster raster = img.getRaster();
WritableRaster rowRaster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, 1, width * 4, 4, new int[]{2, 1, 0, 3}, null);
byte[] row = ((DataBufferByte) rowRaster.getDataBuffer()).getData();
for (int i = 0; i < height; i++) {
int line = isTopDown ? i : height - 1 - i;
rowRaster.setDataElements(0, 0, raster.createChild(0, line, width, 1, 0, 0, new int[]{2, 1, 0, 3}));
imageOutput.write(row);
if (abortRequested()) {
processWriteAborted();
break;
}
processImageProgress(100f * i / (float) height);
}
}
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testConvertByteRGBWhite() {
FastCMYKToRGB convert = new FastCMYKToRGB();
WritableRaster input = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, 1, 1, 4, null);
WritableRaster result = convert.filter(input, null);
byte[] pixel = (byte[]) result.getDataElements(0, 0, null);
assertNotNull(pixel);
assertEquals(3, pixel.length);
byte[] expected = {(byte) 255, (byte) 255, (byte) 255};
assertTrue(String.format("Was: %s, expected: %s", Arrays.toString(pixel), Arrays.toString(expected)), Arrays.equals(expected, pixel));
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testConvertByteABGRColors() {
FastCMYKToRGB convert = new FastCMYKToRGB();
WritableRaster input = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, 1, 1, 4, null);
WritableRaster result = new BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR).getRaster();
byte[] pixel = null;
for (int i = 0; i < 255; i++) {
input.setDataElements(0, 0, new byte[] {(byte) i, (byte) (255 - i), (byte) (128 + i), 0});
result = convert.filter(input, result);
pixel = (byte[]) result.getDataElements(0, 0, pixel);
assertNotNull(pixel);
assertEquals(4, pixel.length);
byte[] expected = {(byte) (255 - i), (byte) i, (byte) (127 - i), (byte) 0xff};
assertTrue(String.format("Was: %s, expected: %s", Arrays.toString(pixel), Arrays.toString(expected)), Arrays.equals(expected, pixel));
}
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testConvertIntRGBWhite() {
FastCMYKToRGB convert = new FastCMYKToRGB();
WritableRaster input = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, 1, 1, 4, null);
WritableRaster result = convert.filter(input, new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB).getRaster());
int[] pixel = (int[]) result.getDataElements(0, 0, null);
assertNotNull(pixel);
assertEquals(1, pixel.length);
int expected = 0xFFFFFF;
int rgb = pixel[0] & 0xFFFFFF;
assertEquals(String.format("Was: 0x%08x, expected: 0x%08x", rgb, expected), expected, rgb);
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testConvertByteRGBBlack() {
FastCMYKToRGB convert = new FastCMYKToRGB();
WritableRaster input = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, 1, 1, 4, null);
WritableRaster result = null;
byte[] pixel = null;
for (int i = 0; i < 255; i++) {
input.setDataElements(0, 0, new byte[] {(byte) i, (byte) (255 - i), (byte) (127 + i), (byte) 255});
result = convert.filter(input, result);
pixel = (byte[]) result.getDataElements(0, 0, pixel);
assertNotNull(pixel);
assertEquals(3, pixel.length);
byte[] expected = {(byte) 0, (byte) 0, (byte) 0};
assertTrue(String.format("Was: %s, expected: %s", Arrays.toString(pixel), Arrays.toString(expected)), Arrays.equals(expected, pixel));
}
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testConvertByteBGRColors() {
FastCMYKToRGB convert = new FastCMYKToRGB();
WritableRaster input = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, 1, 1, 4, null);
WritableRaster result = null;
byte[] pixel = null;
for (int i = 0; i < 255; i++) {
input.setDataElements(0, 0, new byte[] {(byte) i, (byte) (255 - i), (byte) (128 + i), 0});
result = convert.filter(input, result);
pixel = (byte[]) result.getDataElements(0, 0, pixel);
assertNotNull(pixel);
assertEquals(3, pixel.length);
byte[] expected = {(byte) (255 - i), (byte) i, (byte) (127 - i)};
assertTrue(String.format("Was: %s, expected: %s", Arrays.toString(pixel), Arrays.toString(expected)), Arrays.equals(expected, pixel));
}
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testConvertByteRGBColors() {
FastCMYKToRGB convert = new FastCMYKToRGB();
WritableRaster input = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, 1, 1, 4, null);
WritableRaster result = null;
byte[] pixel = null;
for (int i = 0; i < 255; i++) {
input.setDataElements(0, 0, new byte[] {(byte) i, (byte) (255 - i), (byte) (128 + i), 0});
result = convert.filter(input, result);
pixel = (byte[]) result.getDataElements(0, 0, pixel);
assertNotNull(pixel);
assertEquals(3, pixel.length);
byte[] expected = {(byte) (255 - i), (byte) i, (byte) (127 - i)};
assertTrue(String.format("Was: %s, expected: %s", Arrays.toString(pixel), Arrays.toString(expected)), Arrays.equals(expected, pixel));
}
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testConvertIntRGBColors() {
FastCMYKToRGB convert = new FastCMYKToRGB();
WritableRaster input = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, 1, 1, 4, null);
WritableRaster result = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB).getRaster();
int[] pixel = null;
for (int i = 0; i < 255; i++) {
input.setDataElements(0, 0, new byte[] {(byte) i, (byte) (255 - i), (byte) (128 + i), 0});
result = convert.filter(input, result);
pixel = (int[]) result.getDataElements(0, 0, pixel);
assertNotNull(pixel);
assertEquals(1, pixel.length);
int expected = (((byte) (255 - i)) & 0xFF) << 16 | (((byte) i) & 0xFF) << 8 | ((byte) (127 - i)) & 0xFF;
int rgb = pixel[0] & 0xFFFFFF;
assertEquals(String.format("Was: 0x%08x, expected: 0x%08x", rgb, expected), expected, rgb);
}
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testConvertIntARGBColors() {
FastCMYKToRGB convert = new FastCMYKToRGB();
WritableRaster input = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, 1, 1, 4, null);
WritableRaster result = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB).getRaster();
int[] pixel = null;
for (int i = 0; i < 255; i++) {
input.setDataElements(0, 0, new byte[]{(byte) i, (byte) (255 - i), (byte) (128 + i), 0});
result = convert.filter(input, result);
pixel = (int[]) result.getDataElements(0, 0, pixel);
assertNotNull(pixel);
assertEquals(1, pixel.length);
int expected = 0xFF << 24 | (((byte) (255 - i)) & 0xFF) << 16 | (((byte) i) & 0xFF) << 8 | ((byte) (127 - i)) & 0xFF;
assertEquals(String.format("Was: 0x%08x, expected: 0x%08x", pixel[0], expected), expected, pixel[0]);
}
}
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testConvertIntRGBBlack() {
FastCMYKToRGB convert = new FastCMYKToRGB();
WritableRaster input = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, 1, 1, 4, null);
WritableRaster result = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB).getRaster();
int[] pixel = null;
for (int i = 0; i < 255; i++) {
input.setDataElements(0, 0, new byte[] {(byte) i, (byte) (255 - i), (byte) (127 + i), (byte) 255});
result = convert.filter(input, result);
pixel = (int[]) result.getDataElements(0, 0, pixel);
assertNotNull(pixel);
assertEquals(1, pixel.length);
int expected = 0x0;
int rgb = pixel[0] & 0xFFFFFF;
assertEquals(String.format("Was: 0x%08x, expected: 0x%08x", rgb, expected), expected, rgb);
}
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testConvertIntBGRColors() {
FastCMYKToRGB convert = new FastCMYKToRGB();
WritableRaster input = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, 1, 1, 4, null);
WritableRaster result = new BufferedImage(1, 1, BufferedImage.TYPE_INT_BGR).getRaster();
int[] pixel = null;
for (int i = 0; i < 255; i++) {
input.setDataElements(0, 0, new byte[] {(byte) i, (byte) (255 - i), (byte) (128 + i), 0});
result = convert.filter(input, result);
pixel = (int[]) result.getDataElements(0, 0, pixel);
assertNotNull(pixel);
assertEquals(1, pixel.length);
int expected = (((byte) (127 - i)) & 0xFF) << 16 | (((byte) i) & 0xFF) << 8 | ((byte) (255 - i)) & 0xFF;
int rgb = pixel[0] & 0xFFFFFF;
assertEquals(String.format("Was: 0x%08x, expected: 0x%08x", rgb, expected), expected, rgb);
}
}
代码示例来源:origin: haraldk/TwelveMonkeys
WritableRaster raster = Raster.createInterleavedRaster(
buffer, pBitmap.getWidth(), pBitmap.getHeight(), scanlineStride, 3, bOffs, null
);
内容来源于网络,如有侵权,请联系作者删除!