当前位置: 首页>>代码示例>>Java>>正文


Java Raster.createWritableRaster方法代码示例

本文整理汇总了Java中java.awt.image.Raster.createWritableRaster方法的典型用法代码示例。如果您正苦于以下问题:Java Raster.createWritableRaster方法的具体用法?Java Raster.createWritableRaster怎么用?Java Raster.createWritableRaster使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.image.Raster的用法示例。


在下文中一共展示了Raster.createWritableRaster方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toImage

import java.awt.image.Raster; //导入方法依赖的package包/类
/**
 * Convert {@link AbstractImage} to {@link Image}.
 *
 * @param in
 *            the input image
 * @return the converted image
 */
public static Image toImage(AbstractImage in) {
	if (in == null) {
		return null;
	}
	BufferedImage res = new BufferedImage(in.width, in.height, BufferedImage.TYPE_INT_ARGB);
	int[] pixels = new int[in.pixels.length];
	for (int i = 0; i < pixels.length; i += 1) {
		pixels[i] = in.pixels[i] & 0xFF;
	}
	WritableRaster raster = Raster.createWritableRaster(res.getSampleModel(), null);
	raster.setPixels(0, 0, in.width, in.height, pixels);
	res.setData(raster);
	res.flush();
	return res;

}
 
开发者ID:rekit-group,项目名称:rekit-game,代码行数:24,代码来源:ImageManagement.java

示例2: makeImage

import java.awt.image.Raster; //导入方法依赖的package包/类
BufferedImage makeImage() {
// Generate 8-bit image

    //Image img8;
    byte[] pixels8;
    int color16;

    pixels8 = new byte[width*height];
    for (int i=0; i<width*height; i++) {
        color16 = rgb(pixels32[i]);
        pixels8[i] = (byte)hist[color16];
    }

    SampleModel sampleModel = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, width, height, 1, width, new int[] {0});
    DataBufferByte Buffer = new DataBufferByte(pixels8, pixels8.length);
    WritableRaster raster = Raster.createWritableRaster(sampleModel, Buffer, null);

    return new BufferedImage(cm, raster, false, null);
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:20,代码来源:MedianCut.java

示例3: getImage

import java.awt.image.Raster; //导入方法依赖的package包/类
@Override
public BufferedImage getImage()
{

	ByteBuffer buffer = this.getImageBytes();

	if (buffer == null)
	{
		LOG.error("Images bytes buffer is null!");
		return null;
	}

	byte[] bytes = new byte[this.size.width * this.size.height * 3];
	byte[][] data = new byte[][] { bytes };

	buffer.get(bytes);

	DataBufferByte dbuf = new DataBufferByte(data, bytes.length, OFFSET);
	WritableRaster raster = Raster.createWritableRaster(this.smodel, dbuf, null);

	BufferedImage bi = new BufferedImage(this.cmodel, raster, false, null);
	bi.flush();

	return bi;
}
 
开发者ID:PolyphasicDevTeam,项目名称:NoMoreOversleeps,代码行数:26,代码来源:WebcamDefaultDevice.java

示例4: createFloatBufferedImage

import java.awt.image.Raster; //导入方法依赖的package包/类
BufferedImage createFloatBufferedImage(int w, int h, int bands) {
    // Define dimensions and layout of the image
    //int bands = 4; // 4 bands for ARGB, 3 for RGB etc
    int[] bandOffsets = {0, 1, 2, 3}; // length == bands, 0 == R, 1 == G, 2 == B and 3 == A

    // Create a TYPE_FLOAT sample model (specifying how the pixels are stored)
    SampleModel sampleModel = new PixelInterleavedSampleModel(DataBuffer.TYPE_FLOAT, w, h, bands, w  * bands, bandOffsets);
    // ...and data buffer (where the pixels are stored)
    DataBuffer buffer = new DataBufferFloat(w * h * bands);

    // Wrap it in a writable raster
    WritableRaster raster = Raster.createWritableRaster(sampleModel, buffer, null);

    // Create a color model compatible with this sample model/raster (TYPE_FLOAT)
    // Note that the number of bands must equal the number of color components in the 
    // color space (3 for RGB) + 1 extra band if the color model contains alpha 
    ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorModel colorModel = new ComponentColorModel(colorSpace, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_FLOAT);

    // And finally create an image with this raster
    return new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null);
}
 
开发者ID:iapafoto,项目名称:DicomViewer,代码行数:23,代码来源:OpenCLWithJOCL.java

示例5: allocateRgbImage

import java.awt.image.Raster; //导入方法依赖的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);
}
 
开发者ID:etomica,项目名称:etomica,代码行数:32,代码来源:Image.java

示例6: getThumbnail

import java.awt.image.Raster; //导入方法依赖的package包/类
BufferedImage getThumbnail(ImageInputStream iis,
                           JPEGImageReader reader)
    throws IOException {
    iis.mark();
    iis.seek(streamPos);
    // read the palette
    byte [] palette = new byte [PALETTE_SIZE];
    float palettePart = ((float) PALETTE_SIZE) / getLength();
    readByteBuffer(iis,
                   palette,
                   reader,
                   palettePart,
                   0.0F);
    DataBufferByte buffer = new DataBufferByte(thumbWidth*thumbHeight);
    readByteBuffer(iis,
                   buffer.getData(),
                   reader,
                   1.0F-palettePart,
                   palettePart);
    iis.read();
    iis.reset();

    IndexColorModel cm = new IndexColorModel(8,
                                             256,
                                             palette,
                                             0,
                                             false);
    SampleModel sm = cm.createCompatibleSampleModel(thumbWidth,
                                                    thumbHeight);
    WritableRaster raster =
        Raster.createWritableRaster(sm, buffer, null);
    return new BufferedImage(cm,
                             raster,
                             false,
                             null);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:JFIFMarkerSegment.java

示例7: doTest

import java.awt.image.Raster; //导入方法依赖的package包/类
private static void doTest(int dataType) {
    int maxSize = DataBuffer.getDataTypeSize(dataType);
    System.out.println("Type size: " + maxSize);

    int theMask = (int)(1L << (maxSize + 2)) - 1;
    System.out.printf("theMask=%x\n", theMask);

    SinglePixelPackedSampleModel sm =
        new SinglePixelPackedSampleModel(dataType, w, h,
                                         new int[] { theMask });


    int[] sampleSize = sm.getSampleSize();
    for (int s : sampleSize) {
        if (s > maxSize) {
            throw new RuntimeException("Test failed: sample size is too big:" + s);
        }
    }

    System.out.println("Test medialib...");
    DataBuffer buf = createDataBuffer(dataType);

    WritableRaster wr = Raster.createWritableRaster(sm, buf, null);

    op.filter(wr, null);
    System.out.println("Test PASSED.");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:28,代码来源:IncorrectSampleMaskTest.java

示例8: main

import java.awt.image.Raster; //导入方法依赖的package包/类
public static void main(String args[]) {
    BufferedImage src
        = new BufferedImage(1, 10, BufferedImage.TYPE_INT_ARGB);

    // Set src pixel values
    Color pelColor = new Color(100, 100, 100, 128);
    for (int i = 0; i < 10; i++) {
        src.setRGB(0, i, pelColor.getRGB());
    }

    ColorModel cm = new ComponentColorModel
        (ColorSpace.getInstance(ColorSpace.CS_GRAY),
         new int [] {8,8}, true,
         src.getColorModel().isAlphaPremultiplied(),
         Transparency.TRANSLUCENT,
         DataBuffer.TYPE_BYTE);

    SampleModel sm = new PixelInterleavedSampleModel
        (DataBuffer.TYPE_BYTE, 100, 100, 2, 200,
         new int [] { 0, 1 });

    WritableRaster wr = Raster.createWritableRaster(sm, new Point(0,0));

    BufferedImage dst =
        new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
    dst = dst.getSubimage(0, 0, 1, 10);

    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(src, dst);

    for (int i = 0; i < 10; i++) {
        if (((dst.getRGB(0, i) >> 24) & 0xff) != 128) {
            throw new RuntimeException(
                "Incorrect destination alpha value.");
        }
    }

}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:40,代码来源:ColCvtAlpha.java

示例9: getGrayscale

import java.awt.image.Raster; //导入方法依赖的package包/类
/**
 *
 * @param width The image width (height derived from buffer length)
 * @param buffer The buffer containing raw grayscale pixel data
 *
 * @return THe grayscale image
 */
public static BufferedImage getGrayscale(int width, byte[] buffer) {
    int height = buffer.length / width;
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
    int[] nBits = { 8 };
    ColorModel cm = new ComponentColorModel(cs, nBits, false, true, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
    SampleModel sm = cm.createCompatibleSampleModel(width, height);
    DataBufferByte db = new DataBufferByte(buffer, width * height);
    WritableRaster raster = Raster.createWritableRaster(sm, db, null);
    BufferedImage result = new BufferedImage(cm, raster, false, null);
    return result;
}
 
开发者ID:marcelrv,项目名称:XiaomiRobotVacuumProtocol,代码行数:19,代码来源:RRDraw.java

示例10: createBufferedImage

import java.awt.image.Raster; //导入方法依赖的package包/类
/**
 * Creates a <code>BufferedImage</code> with a given width and
 * height according to the specification embodied in this object.
 *
 * @param width the desired width of the returned
 * <code>BufferedImage</code>.
 * @param height the desired height of the returned
 * <code>BufferedImage</code>.
 *
 * @return a new <code>BufferedImage</code>
 *
 * @exception IllegalArgumentException if either <code>width</code> or
 * <code>height</code> are negative or zero.
 * @exception IllegalArgumentException if the product of
 * <code>width</code> and <code>height</code> is greater than
 * <code>Integer.MAX_VALUE</code>, or if the number of array
 * elements needed to store the image is greater than
 * <code>Integer.MAX_VALUE</code>.
 */
public BufferedImage createBufferedImage(int width, int height) {
    try {
        SampleModel sampleModel = getSampleModel(width, height);
        WritableRaster raster =
            Raster.createWritableRaster(sampleModel,
                                        new Point(0, 0));
        return new BufferedImage(colorModel, raster,
                                 colorModel.isAlphaPremultiplied(),
                                 new Hashtable());
    } catch (NegativeArraySizeException e) {
        // Exception most likely thrown from a DataBuffer constructor
        throw new IllegalArgumentException
            ("Array size > Integer.MAX_VALUE!");
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:35,代码来源:ImageTypeSpecifier.java

示例11: copyData

import java.awt.image.Raster; //导入方法依赖的package包/类
/**
 * Copies an arbitrary rectangular region of the RenderedImage
 * into a caller-supplied WritableRaster.  The region to be
 * computed is determined by clipping the bounds of the supplied
 * WritableRaster against the bounds of the image.  The supplied
 * WritableRaster must have a SampleModel that is compatible with
 * that of the image.
 *
 * <p> If the raster argument is null, the entire image will
 * be copied into a newly-created WritableRaster with a SampleModel
 * that is compatible with that of the image.
 *
 * @param dest a WritableRaster to hold the returned portion of
 *        the image.
 * @return a reference to the supplied WritableRaster, or to a
 *         new WritableRaster if the supplied one was null.
 */
public WritableRaster copyData(WritableRaster dest) {
    // Get the image bounds.
    Rectangle imageBounds = getBounds();

    Rectangle bounds;
    if (dest == null) {
        // Create a WritableRaster for the entire image.
        bounds = imageBounds;
        Point p = new Point(minX, minY);
        SampleModel sm =
            sampleModel.createCompatibleSampleModel(width, height);
        dest = Raster.createWritableRaster(sm, p);
    } else {
        bounds = dest.getBounds();
    }

    // Determine tile limits for the intersection of the prescribed
    // bounds with the image bounds.
    Rectangle xsect = imageBounds.contains(bounds) ?
        bounds : bounds.intersection(imageBounds);
    int startX = XToTileX(xsect.x);
    int startY = YToTileY(xsect.y);
    int endX = XToTileX(xsect.x + xsect.width - 1);
    int endY = YToTileY(xsect.y + xsect.height - 1);

    // Loop over the tiles in the intersection.
    for (int j = startY; j <= endY; j++) {
        for (int i = startX; i <= endX; i++) {
            // Retrieve the tile.
            Raster tile = getTile(i, j);

            // Create a child of the tile for the intersection of
            // the tile bounds and the bounds of the requested area.
            Rectangle tileRect = tile.getBounds();
            Rectangle intersectRect =
                bounds.intersection(tile.getBounds());
            Raster liveRaster = tile.createChild(intersectRect.x,
                                                 intersectRect.y,
                                                 intersectRect.width,
                                                 intersectRect.height,
                                                 intersectRect.x,
                                                 intersectRect.y,
                                                 null);

            // Copy the data from the child.
            dest.setRect(liveRaster);
        }
    }

    return dest;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:69,代码来源:SimpleRenderedImage.java

示例12: createBufferedImage

import java.awt.image.Raster; //导入方法依赖的package包/类
/**
 * Creates a {@code BufferedImage} with a given width and
 * height according to the specification embodied in this object.
 *
 * @param width the desired width of the returned
 * {@code BufferedImage}.
 * @param height the desired height of the returned
 * {@code BufferedImage}.
 *
 * @return a new {@code BufferedImage}
 *
 * @exception IllegalArgumentException if either {@code width} or
 * {@code height} are negative or zero.
 * @exception IllegalArgumentException if the product of
 * {@code width} and {@code height} is greater than
 * {@code Integer.MAX_VALUE}, or if the number of array
 * elements needed to store the image is greater than
 * {@code Integer.MAX_VALUE}.
 */
public BufferedImage createBufferedImage(int width, int height) {
    try {
        SampleModel sampleModel = getSampleModel(width, height);
        WritableRaster raster =
            Raster.createWritableRaster(sampleModel,
                                        new Point(0, 0));
        return new BufferedImage(colorModel, raster,
                                 colorModel.isAlphaPremultiplied(),
                                 new Hashtable<>());
    } catch (NegativeArraySizeException e) {
        // Exception most likely thrown from a DataBuffer constructor
        throw new IllegalArgumentException
            ("Array size > Integer.MAX_VALUE!");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:ImageTypeSpecifier.java


注:本文中的java.awt.image.Raster.createWritableRaster方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。