當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。