當前位置: 首頁>>代碼示例>>Java>>正文


Java Raster.createInterleavedRaster方法代碼示例

本文整理匯總了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);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:72,代碼來源:WDataTransferer.java

示例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);
}
 
開發者ID:scriptkittie,項目名稱:GlitchKernel,代碼行數:32,代碼來源:DataAsSound.java

示例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);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:32,代碼來源:JFIFMarkerSegment.java

示例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);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:13,代碼來源:Win32ColorModel24.java

示例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);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:15,代碼來源:BMPSubsamplingTest.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:TestChildRasterOp.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:TestChildRasterOp.java

示例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);
}
 
開發者ID:scriptkittie,項目名稱:GlitchKernel,代碼行數:7,代碼來源:DataBend.java

示例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;
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:7,代碼來源:ImageConverter.java

示例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;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:7,代碼來源:EdgeNoOpCrash.java

示例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;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:7,代碼來源:EdgeNoOpCrash.java


注:本文中的java.awt.image.Raster.createInterleavedRaster方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。