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