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


Java WritableRaster类代码示例

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


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

示例1: createAnBlankAndWhitePngImage

import java.awt.image.WritableRaster; //导入依赖的package包/类
@Test
public void createAnBlankAndWhitePngImage() throws IOException {
    int m = 5;
    int n = 5;
    BufferedImage image = new BufferedImage(m, n, BufferedImage.TYPE_BYTE_BINARY);
    WritableRaster raster = image.getRaster();

    for (int x = 0; x < m; x++) {
        for (int y = 0; y < m; y++) {
            int index = (x + y) % 2 == 0 ? 1: 0;
            raster.setPixel(x, y, new int[]{ index });
        }
    }

    File output = new File("src/test/resources/png-test.black-white.png");
    ImageIO.write(image, "png", output);
}
 
开发者ID:fifth-postulate,项目名称:finding-the-planets,代码行数:18,代码来源:ImageTest.java

示例2: setPixels

import java.awt.image.WritableRaster; //导入依赖的package包/类
/**
 * <p>Writes a rectangular area of pixels in the destination <code>BufferedImage</code>. Calling this method on an
 * image of type different from <code>BufferedImage.TYPE_INT_ARGB</code> and <code>BufferedImage.TYPE_INT_RGB</code>
 * will unmanage the image.</p>
 *
 * @param img    the destination image
 * @param x      the x location at which to start storing pixels
 * @param y      the y location at which to start storing pixels
 * @param w      the width of the rectangle of pixels to store
 * @param h      the height of the rectangle of pixels to store
 * @param pixels an array of pixels, stored as integers
 * @throws IllegalArgumentException is <code>pixels</code> is non-null and of length &lt; w*h
 */
static void setPixels(BufferedImage img,
                             int x, int y, int w, int h, byte[] pixels) {
    if (pixels == null || w == 0 || h == 0) {
        return;
    } else if (pixels.length < w * h) {
        throw new IllegalArgumentException("pixels array must have a length >= w*h");
    }
    int imageType = img.getType();
    if (imageType == BufferedImage.TYPE_BYTE_GRAY) {
        WritableRaster raster = img.getRaster();
        raster.setDataElements(x, y, w, h, pixels);
    } else {
        throw new IllegalArgumentException("Only type BYTE_GRAY is supported");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:EffectUtils.java

示例3: convert

import java.awt.image.WritableRaster; //导入依赖的package包/类
@Override
public String convert(FieldAccessor fa, Instance instance) throws FieldAccessor.InvalidFieldException {
    Instance raster = fa.getInstance(instance, "raster", WritableRaster.class, true);   // NOI18N
    int width = fa.getInt(raster, "width");   // NOI18N
    int height = fa.getInt(raster, "height");   // NOI18N
    Instance colorModel = fa.getInstance(instance, "colorModel", ColorModel.class, true);

    int color_count = 0;
    if (FieldAccessor.isInstanceOf(colorModel, IndexColorModel.class)) {
        color_count = DetailsUtils.getIntFieldValue(colorModel, "map_size", 0); // NOI18N
    }
    if (color_count > 0) {
        return Bundle.ImageDetailProvider_ImageDescrColors(width, height, color_count);
    } else {
        return Bundle.ImageDetailProvider_ImageDescr(width, height);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:ImageBuilder.java

示例4: renderGlyph

import java.awt.image.WritableRaster; //导入依赖的package包/类
/**
 * Loads a single glyph to the backing texture, if it fits.
 * 
 * @param glyph The glyph to be rendered
 * @param width The expected width of the glyph
 * @param height The expected height of the glyph
 * @throws SlickException if the glyph could not be rendered.
 */
private void renderGlyph(Glyph glyph, int width, int height) throws SlickException {
	// Draw the glyph to the scratch image using Java2D.
	scratchGraphics.setComposite(AlphaComposite.Clear);
	scratchGraphics.fillRect(0, 0, MAX_GLYPH_SIZE, MAX_GLYPH_SIZE);
	scratchGraphics.setComposite(AlphaComposite.SrcOver);
	scratchGraphics.setColor(java.awt.Color.white);
	for (Iterator iter = unicodeFont.getEffects().iterator(); iter.hasNext();)
		((Effect)iter.next()).draw(scratchImage, scratchGraphics, unicodeFont, glyph);
	glyph.setShape(null); // The shape will never be needed again.

	WritableRaster raster = scratchImage.getRaster();
	int[] row = new int[width];
	for (int y = 0; y < height; y++) {
		raster.getDataElements(0, y, width, 1, row);
		scratchIntBuffer.put(row);
	}
	GL.glTexSubImage2D(SGL.GL_TEXTURE_2D, 0, pageX, pageY, width, height, SGL.GL_BGRA, SGL.GL_UNSIGNED_BYTE,
		scratchByteBuffer);
	scratchIntBuffer.clear();

	glyph.setImage(pageImage.getSubImage(pageX, pageY, width, height));
}
 
开发者ID:IngSW-unipv,项目名称:Progetto-C,代码行数:31,代码来源:GlyphPage.java

示例5: getPixeisVizinhos3x3

import java.awt.image.WritableRaster; //导入依赖的package包/类
public static List<Integer> getPixeisVizinhos3x3(BufferedImage img, int i, int j, int tipoPixel) {
	List<Integer> pixeisVizinhos = new ArrayList<>();
	WritableRaster raster = img.getRaster();
	int pixels[] = new int[4];
	pixeisVizinhos.add(raster.getPixel(i - 1, j - 1, pixels)[tipoPixel]);
	pixeisVizinhos.add(raster.getPixel(i - 1, j, pixels)[tipoPixel]);
	pixeisVizinhos.add(raster.getPixel(i - 1, j + 1, pixels)[tipoPixel]);
	pixeisVizinhos.add(raster.getPixel(i, j - 1, pixels)[tipoPixel]);
	pixeisVizinhos.add(raster.getPixel(i, j, pixels)[tipoPixel]);
	pixeisVizinhos.add(raster.getPixel(i, j + 1, pixels)[tipoPixel]);
	pixeisVizinhos.add(raster.getPixel(i + 1, j - 1, pixels)[tipoPixel]);
	pixeisVizinhos.add(raster.getPixel(i + 1, j, pixels)[tipoPixel]);
	pixeisVizinhos.add(raster.getPixel(i + 1, j + 1, pixels)[tipoPixel]);

	Collections.sort(pixeisVizinhos);

	return pixeisVizinhos;
}
 
开发者ID:nbfontana,项目名称:pdi,代码行数:19,代码来源:PixelsUtils.java

示例6: eval

import java.awt.image.WritableRaster; //导入依赖的package包/类
public BufferedImage eval() throws Exception {
  if (dw < 1 || dh < 1) return ImageUtils.NULL_IMAGE;

  // ensure that src is a type which GeneralFilter can handle
  final BufferedImage src = ImageUtils.coerceToIntType(sop.getImage(null));

  final Rectangle sr =
    new Rectangle(0, 0,
                  (int)(sop.getWidth()*scale),
                  (int)(sop.getHeight()*scale));

  final WritableRaster dstR = src.getColorModel()
                                 .createCompatibleWritableRaster(dw, dh)
                                 .createWritableTranslatedChild(dx0, dy0);
  // zoom! zoom!
  GeneralFilter.zoom(dstR, sr, src, scale < 1.0f ? downFilter : upFilter);

  return ImageUtils.toCompatibleImage(new BufferedImage(
    src.getColorModel(),
    dstR.createWritableTranslatedChild(0,0),
    src.isAlphaPremultiplied(),
    null
  ));
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:25,代码来源:ScaleOpBitmapImpl.java

示例7: sliceTile

import java.awt.image.WritableRaster; //导入依赖的package包/类
@Override
protected BufferedImage sliceTile() {
  // get actual tile width, height (edge tiles can be less than full size)
  final int atw = Math.min(tw, dw - tx*tw);
  final int ath = Math.min(th, dh - ty*th);

  final int type = src.getType();

  // scale the tile from the source image
  final BufferedImage tile = new BufferedImage(atw, ath, type);

  final WritableRaster tileR =
    tile.getRaster().createWritableTranslatedChild(tx*tw, ty*th);
  final Rectangle dstFR = new Rectangle(0, 0, dw, dh);

  GeneralFilter.zoom(tileR, dstFR, src, filter);

  return tile;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:20,代码来源:ScaledTileTask.java

示例8: getIndexedImage

import java.awt.image.WritableRaster; //导入依赖的package包/类
protected RenderedImage getIndexedImage() {
    IndexColorModel icm = getIndexColorModel();

    BufferedImage dst =
        new BufferedImage(src.getWidth(), src.getHeight(),
                          BufferedImage.TYPE_BYTE_INDEXED, icm);

    WritableRaster wr = dst.getRaster();
    for (int y =0; y < dst.getHeight(); y++) {
        for (int x = 0; x < dst.getWidth(); x++) {
            Color aColor = getSrcColor(x,y);
            wr.setSample(x, y, 0, findColorIndex(root, aColor));
        }
    }

    return dst;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:PaletteBuilder.java

示例9: getSplits

import java.awt.image.WritableRaster; //导入依赖的package包/类
private static int[] getSplits(BufferedImage image, String name) {
    WritableRaster raster = image.getRaster();
    int startX = getSplitPoint(raster, name, 1, 0, true, true);
    int endX = getSplitPoint(raster, name, startX, 0, false, true);
    int startY = getSplitPoint(raster, name, 0, 1, true, false);
    int endY = getSplitPoint(raster, name, 0, startY, false, false);
    getSplitPoint(raster, name, endX + 1, 0, true, true);
    getSplitPoint(raster, name, 0, endY + 1, true, false);
    if (startX == 0 && endX == 0 && startY == 0 && endY == 0) return null;
    if (startX != 0) {
        startX--;
        endX = raster.getWidth() - 2 - (endX - 1);
    } else {
        endX = raster.getWidth() - 2;
    }
    if (startY != 0) {
        startY--;
        endY = raster.getHeight() - 2 - (endY - 1);
    } else {
        endY = raster.getHeight() - 2;
    }
    return new int[]{startX, endX, startY, endY};
}
 
开发者ID:dmitrykolesnikovich,项目名称:featurea,代码行数:24,代码来源:ImageProcessor.java

示例10: crashTest

import java.awt.image.WritableRaster; //导入依赖的package包/类
private static void crashTest() {
    Raster src = createSrcRaster();
    WritableRaster dst = createDstRaster();
    ConvolveOp op = createConvolveOp(ConvolveOp.EDGE_NO_OP);
    try {
        op.filter(src, dst);
    } catch (ImagingOpException e) {
        /*
         * The test pair of source and destination rasters
         * may cause failure of the medialib convolution routine,
         * so this exception is expected.
         *
         * The JVM crash is the only manifestation of this
         * test failure.
         */
    }
    System.out.println("Test PASSED.");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:EdgeNoOpCrash.java

示例11: thresholdImage

import java.awt.image.WritableRaster; //导入依赖的package包/类
public BufferedImage thresholdImage(BufferedImage image, int threshold) {
    BufferedImage result = new BufferedImage(image.getWidth(), 
            image.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
    result.getGraphics().drawImage(image, 0, 0, null);
    WritableRaster raster = result.getRaster();
    int[] pixels = new int[image.getWidth()];
    for (int y = 0; y < image.getHeight(); y++) {
        raster.getPixels(0, y, image.getWidth(), 1, pixels);
        for (int i = 0; i < pixels.length; i++) {
            if (pixels[i] < threshold) {
                pixels[i] = 0;
            } else {
                pixels[i] = 255;
            }
        }
        raster.setPixels(0, y, image.getWidth(), 1, pixels);
    }
    return result;
}
 
开发者ID:varunon9,项目名称:Image-Stegano,代码行数:20,代码来源:ImageUtility.java

示例12: setPixels

import java.awt.image.WritableRaster; //导入依赖的package包/类
/**
 * <p>Writes a rectangular area of pixels in the destination
 * <code>BufferedImage</code>. Calling this method on
 * an image of type different from <code>BufferedImage.TYPE_INT_ARGB</code>
 * and <code>BufferedImage.TYPE_INT_RGB</code> will unmanage the image.</p>
 *
 * @param img the destination image
 * @param x the x location at which to start storing pixels
 * @param y the y location at which to start storing pixels
 * @param w the width of the rectangle of pixels to store
 * @param h the height of the rectangle of pixels to store
 * @param pixels an array of pixels, stored as integers
 * @throws IllegalArgumentException is <code>pixels</code> is non-null and
 *   of length &lt; w*h
 */
public static void setPixels(BufferedImage img,
                             int x, int y, int w, int h, int[] pixels) {
    if (pixels == null || w == 0 || h == 0) {
        return;
    } else if (pixels.length < w * h) {
        throw new IllegalArgumentException("pixels array must have a length" +
                                           " >= w*h");
    }

    int imageType = img.getType();
    if (imageType == BufferedImage.TYPE_INT_ARGB ||
        imageType == BufferedImage.TYPE_INT_RGB) {
        WritableRaster raster = img.getRaster();
        raster.setDataElements(x, y, w, h, pixels);
    } else {
        // Unmanages the image
        img.setRGB(x, y, w, h, pixels, 0, w);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:35,代码来源:EffectUtils.java

示例13: getRaster

import java.awt.image.WritableRaster; //导入依赖的package包/类
public synchronized Raster getRaster(int x, int y, int w, int h) {
    WritableRaster t = savedTile;

    if (t == null || w > t.getWidth() || h > t.getHeight()) {
        t = getColorModel().createCompatibleWritableRaster(w, h);
        IntegerComponentRaster icr = (IntegerComponentRaster) t;
        Arrays.fill(icr.getDataStorage(), color);
        // Note - markDirty is probably unnecessary since icr is brand new
        icr.markDirty();
        if (w <= 64 && h <= 64) {
            savedTile = t;
        }
    }

    return t;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:ColorPaintContext.java

示例14: makeByteRaster

import java.awt.image.WritableRaster; //导入依赖的package包/类
static synchronized WritableRaster makeByteRaster(Raster srcRas,
                                                  int w, int h)
{
    if (byteRasRef != null) {
        WritableRaster wr = (WritableRaster) byteRasRef.get();
        if (wr != null && wr.getWidth() >= w && wr.getHeight() >= h) {
            byteRasRef = null;
            return wr;
        }
    }
    // If we are going to cache this Raster, make it non-tiny
    if (w <= 32 && h <= 32) {
        w = h = 32;
    }
    return srcRas.createCompatibleWritableRaster(w, h);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:TexturePaintContext.java

示例15: createComponentImage

import java.awt.image.WritableRaster; //导入依赖的package包/类
protected static BufferedImage createComponentImage(int w, int h,
                                                    ComponentColorModel cm)
{
    WritableRaster wr = cm.createCompatibleWritableRaster(w, h);

    BufferedImage img = new BufferedImage(cm, wr, false, null);
    Graphics2D g = img.createGraphics();
    int width = w / 8;
    Color[] colors = new Color[8];
    colors[0] = Color.red;
    colors[1] = Color.green;
    colors[2] = Color.blue;
    colors[3] = Color.white;
    colors[4] = Color.black;
    colors[5] = new Color(0x80, 0x80, 0x80, 0x00);
    colors[6] = Color.yellow;
    colors[7] = Color.cyan;

    for (int i = 0; i < 8; i++) {
        g.setColor(colors[i]);
        g.fillRect(i * width, 0, width, h);
    }
    return img;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:IndexingTest.java


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