本文整理汇总了Java中java.awt.image.Raster.createInterleavedRaster方法的典型用法代码示例。如果您正苦于以下问题:Java Raster.createInterleavedRaster方法的具体用法?Java Raster.createInterleavedRaster怎么用?Java Raster.createInterleavedRaster使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.image.Raster
的用法示例。
在下文中一共展示了Raster.createInterleavedRaster方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: imageToPlatformBytes
import java.awt.image.Raster; //导入方法依赖的package包/类
@Override
protected byte[] imageToPlatformBytes(Image image, long format)
throws IOException {
String mimeType = null;
if (format == CF_PNG) {
mimeType = "image/png";
} else if (format == CF_JFIF) {
mimeType = "image/jpeg";
}
if (mimeType != null) {
return imageToStandardBytes(image, mimeType);
}
int width = 0;
int height = 0;
if (image instanceof ToolkitImage) {
ImageRepresentation ir = ((ToolkitImage)image).getImageRep();
ir.reconstruct(ImageObserver.ALLBITS);
width = ir.getWidth();
height = ir.getHeight();
} else {
width = image.getWidth(null);
height = image.getHeight(null);
}
// Fix for 4919639.
// Some Windows native applications (e.g. clipbrd.exe) do not handle
// 32-bpp DIBs correctly.
// As a workaround we switched to 24-bpp DIBs.
// MSDN prescribes that the bitmap array for a 24-bpp should consist of
// 3-byte triplets representing blue, green and red components of a
// pixel respectively. Additionally each scan line must be padded with
// zeroes to end on a LONG data-type boundary. LONG is always 32-bit.
// We render the given Image to a BufferedImage of type TYPE_3BYTE_BGR
// with non-default scanline stride and pass the resulting data buffer
// to the native code to fill the BITMAPINFO structure.
int mod = (width * 3) % 4;
int pad = mod > 0 ? 4 - mod : 0;
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
int[] nBits = {8, 8, 8};
int[] bOffs = {2, 1, 0};
ColorModel colorModel =
new ComponentColorModel(cs, nBits, false, false,
Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
WritableRaster raster =
Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, height,
width * 3 + pad, 3, bOffs, null);
BufferedImage bimage = new BufferedImage(colorModel, raster, false, null);
// Some Windows native applications (e.g. clipbrd.exe) do not understand
// top-down DIBs.
// So we flip the image vertically and create a bottom-up DIB.
AffineTransform imageFlipTransform =
new AffineTransform(1, 0, 0, -1, 0, height);
Graphics2D g2d = bimage.createGraphics();
try {
g2d.drawImage(image, imageFlipTransform, null);
} finally {
g2d.dispose();
}
DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer();
byte[] imageData = buffer.getData();
return imageDataToPlatformImageBytes(imageData, width, height, format);
}
示例2: glitchPixels
import java.awt.image.Raster; //导入方法依赖的package包/类
@Override
public byte[] glitchPixels(byte[] inputImageBytes) throws Exception
{
int audioBitRate = ((Integer) getPixelGlitchParameters().get("bitRateBlend")).intValue();
float bitRateBlend = (float) audioBitRate / 10;
if(bitRateBlend < 0.1F || bitRateBlend > 0.9F)
{
return null;
}
BufferedImage inputImage = ImageUtil.getImageFromBytes(inputImageBytes);
InputStream imageInputStream = new ByteArrayInputStream(inputImageBytes);
AudioInputStream distortionAudioStream = new AudioInputStream(imageInputStream, new AudioFormat(AudioFormat.Encoding.ULAW, ThreadLocalRandom.current().nextInt(8000, 20000), 8, 5, 9, ThreadLocalRandom.current().nextInt(8000, 20000), true), inputImageBytes.length);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
AudioSystem.write(distortionAudioStream, Type.WAVE, outputStream);
BufferedImage outputImage = new BufferedImage(inputImage.getWidth(), inputImage.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
byte[] imageData = ((DataBufferByte) outputImage.getRaster().getDataBuffer()).getData();
System.arraycopy(outputStream.toByteArray(),0,imageData,0,outputStream.toByteArray().length);
int[] abgrOffsets = {3, 2, 1, 0};
DataBuffer outputBuffer = new DataBufferByte(imageData, imageData.length);
WritableRaster raster = Raster.createInterleavedRaster(outputBuffer, inputImage.getWidth(), inputImage.getHeight(), 4 * inputImage.getWidth(), 4, abgrOffsets, null);
ColorModel colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
BufferedImage rasterizedImage = new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null);
rasterizedImage = resizeImage(rasterizedImage, inputImage.getWidth() * 4, inputImage.getHeight() * 4);
Graphics2D g2d = rasterizedImage.createGraphics();
g2d.setComposite(AlphaComposite.SrcOver.derive(bitRateBlend));
g2d.drawImage(inputImage, 0, 0, null);
g2d.dispose();
rasterizedImage = rasterizedImage.getSubimage(0, 0, inputImage.getWidth(), inputImage.getHeight());
return ImageUtil.getImageBytes(rasterizedImage);
}
示例3: getThumbnail
import java.awt.image.Raster; //导入方法依赖的package包/类
BufferedImage getThumbnail(ImageInputStream iis,
JPEGImageReader reader)
throws IOException {
iis.mark();
iis.seek(streamPos);
DataBufferByte buffer = new DataBufferByte(getLength());
readByteBuffer(iis,
buffer.getData(),
reader,
1.0F,
0.0F);
iis.reset();
WritableRaster raster =
Raster.createInterleavedRaster(buffer,
thumbWidth,
thumbHeight,
thumbWidth*3,
3,
new int [] {0, 1, 2},
null);
ColorModel cm = new ComponentColorModel(JPEG.JCS.sRGB,
false,
false,
ColorModel.OPAQUE,
DataBuffer.TYPE_BYTE);
return new BufferedImage(cm,
raster,
false,
null);
}
示例4: createCompatibleWritableRaster
import java.awt.image.Raster; //导入方法依赖的package包/类
/**
* Creates a WritableRaster with the specified width and height, that
* has a data layout (SampleModel) compatible with this ColorModel.
* @see WritableRaster
* @see SampleModel
*/
public WritableRaster createCompatibleWritableRaster (int w, int h) {
int[] bOffs = {2, 1, 0};
return Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
w, h, w*3, 3,
bOffs, null);
}
示例5: create3ByteImage
import java.awt.image.Raster; //导入方法依赖的package包/类
private BufferedImage create3ByteImage(int[] nBits, int[] bOffs) {
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
ColorModel colorModel =
new ComponentColorModel(cs, nBits,
false, false,
Transparency.OPAQUE,
DataBuffer.TYPE_BYTE);
WritableRaster raster =
Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
w, h,
w*3, 3,
bOffs, null);
return new BufferedImage(colorModel, raster, false, null);
}
示例6: testByteRaster
import java.awt.image.Raster; //导入方法依赖的package包/类
private static void testByteRaster() {
WritableRaster srcRaster, dstRaster;
byte[] pixels =
{ 11, 12, 13, 14,
21, 22, 23, 24,
31, 32, 33, 34,
41, 42, 43, 44 };
DataBuffer db = new DataBufferByte(pixels, pixels.length);
srcRaster =
Raster.createInterleavedRaster(db, 4, 4, 4, 1, offsets, null);
srcRaster = srcRaster.createWritableChild(1, 1, 3, 3, 0, 0, null);
dstRaster = rop.filter(srcRaster, null);
}
示例7: testShortRaster
import java.awt.image.Raster; //导入方法依赖的package包/类
private static void testShortRaster() {
WritableRaster srcRaster, dstRaster;
short[] pixels =
{ 11, 12, 13, 14,
21, 22, 23, 24,
31, 32, 33, 34,
41, 42, 43, 44 };
DataBuffer db = new DataBufferUShort(pixels, pixels.length);
srcRaster =
Raster.createInterleavedRaster(db, 4, 4, 4, 1, offsets, null);
srcRaster = srcRaster.createWritableChild(1, 1, 3, 3, 0, 0, null);
dstRaster = rop.filter(srcRaster, null);
}
示例8: createRGBImage
import java.awt.image.Raster; //导入方法依赖的package包/类
private static BufferedImage createRGBImage(byte[] bytes, int width, int height)
{
DataBufferByte buffer = new DataBufferByte(bytes, bytes.length);
ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[]{8, 8, 8}, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
return new BufferedImage(cm, Raster.createInterleavedRaster(buffer, width, height, width * 3, 3, new int[]{0, 1, 2}, null), false, null);
}
示例9: createGlCompatibleAwtImage
import java.awt.image.Raster; //导入方法依赖的package包/类
public static BufferedImage createGlCompatibleAwtImage(int width, int height)
{
WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, height, 4, null);
BufferedImage convertImage = new BufferedImage(COLOR_MODEL, raster, false, new Hashtable());
return convertImage;
}
示例10: createSrcRaster
import java.awt.image.Raster; //导入方法依赖的package包/类
private static Raster createSrcRaster() {
WritableRaster r = Raster.createInterleavedRaster(DataBuffer.TYPE_USHORT,
w, h, 4, new Point(0, 0));
return r;
}
示例11: createDstRaster
import java.awt.image.Raster; //导入方法依赖的package包/类
private static WritableRaster createDstRaster() {
WritableRaster r = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
w, h, 4, new Point(0, 0));
return r;
}