WritableRaster raster = model.createCompatibleWritableRaster(width, height); byte[] pixels = ((DataBufferByte) raster.getDataBuffer()).getData(); for (int row = 0; row < height; row++)
/** * Creates a compatible {@code Raster} to dither into. * * @param pSrc the source raster. * @param pIndexColorModel the index color model used to create a {@code Raster}. * * @return a {@code WritableRaster} */ public final WritableRaster createCompatibleDestRaster(Raster pSrc, IndexColorModel pIndexColorModel) { return pIndexColorModel.createCompatibleWritableRaster(pSrc.getWidth(), pSrc.getHeight()); }
public final WritableRaster createCompatibleDestRaster(Raster pSrc, IndexColorModel pIndexColorModel) { return pIndexColorModel.createCompatibleWritableRaster(pSrc.getWidth(), pSrc.getHeight()); }
public WritableRaster createCompatibleDestRaster(Raster src) { return icm.createCompatibleWritableRaster(src.getWidth(), src.getHeight()) .createWritableTranslatedChild(src.getMinX(), src.getMinY()); }
BufferedImage createPaletteImage(final BMHDChunk header, boolean isEHB) throws IIOException { // Create a 1 x colors.length image IndexColorModel cm = getIndexColorModel(header, isEHB); WritableRaster raster = cm.createCompatibleWritableRaster(cm.getMapSize(), 1); byte[] pixel = null; for (int x = 0; x < cm.getMapSize(); x++) { pixel = (byte[]) cm.getDataElements(cm.getRGB(x), pixel); raster.setDataElements(x, 0, pixel); } return new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null); }
public BufferedImage createImageIndexed() { // TODO: This is very stupid, maybe we need a TYPE_CUSTOM image, with separate alphaRaster?! // As ICO has a separate bitmask, not related to palette index (allows 256 colors + trans) :-P IndexColorModel icm = createColorModel(); // This is slightly obscure, and should probably be moved.. Hashtable<String, Object> properties = null; if (entry instanceof DirectoryEntry.CUREntry) { properties = new Hashtable<>(1); properties.put("cursor_hotspot", ((DirectoryEntry.CUREntry) this.entry).getHotspot()); } BufferedImage image = new BufferedImage( icm, icm.createCompatibleWritableRaster(getWidth(), getHeight()), icm.isAlphaPremultiplied(), properties ); WritableRaster raster = image.getRaster(); // Make pixels transparent according to mask final int trans = icm.getTransparentPixel(); for (int y = 0; y < getHeight(); y++) { for (int x = 0; x < getWidth(); x++) { if (mask.isTransparent(x, y)) { bits[x + getWidth() * y] = trans; } } } raster.setSamples(0, 0, getWidth(), getHeight(), 0, bits); return image; }
icm.createCompatibleWritableRaster(src.getWidth(), src.getHeight()); final BufferedImage dst = new BufferedImage(icm, destWr, false, null);
/** * Creates a compatible {@code Raster} to dither into. * * @param pSrc the source raster. * @param pIndexColorModel the index color model used to create a {@code Raster}. * * @return a {@code WritableRaster} */ public final WritableRaster createCompatibleDestRaster(Raster pSrc, IndexColorModel pIndexColorModel) { return pIndexColorModel.createCompatibleWritableRaster(pSrc.getWidth(), pSrc.getHeight()); }
public final WritableRaster createCompatibleDestRaster(Raster pSrc, IndexColorModel pIndexColorModel) { return pIndexColorModel.createCompatibleWritableRaster(pSrc.getWidth(), pSrc.getHeight()); /* return new BufferedImage(pSrc.getWidth(), pSrc.getHeight(), BufferedImage.TYPE_BYTE_INDEXED, pIndexColorModel).getRaster(); */ }
public WritableRaster createCompatibleDestRaster(Raster src) { return icm.createCompatibleWritableRaster(src .getWidth(), src.getHeight()); }
public final WritableRaster createCompatibleDestRaster(Raster pSrc, IndexColorModel pIndexColorModel) { return pIndexColorModel.createCompatibleWritableRaster(pSrc.getWidth(), pSrc.getHeight()); }
raster = pModel.createCompatibleWritableRaster(width, 1);
private static TexturePaint create8x8Pattern(final int pPattern) { // TODO: Creating a special purpose Pattern might be faster than piggy-backing on TexturePaint WritableRaster raster = QuickDraw.MONOCHROME.createCompatibleWritableRaster(8, 8); byte[] data = ((DataBufferByte) raster.getDataBuffer()).getData(); for (int i = 0; i < data.length; i += 4) { data[i ] = (byte) ((pPattern >> 24) & 0xFF); data[i + 1] = (byte) ((pPattern >> 16) & 0xFF); data[i + 2] = (byte) ((pPattern >> 8) & 0xFF); data[i + 3] = (byte) ((pPattern ) & 0xFF); } BufferedImage img = new BufferedImage(QuickDraw.MONOCHROME, raster, false, null); return new TexturePaint(img, new Rectangle(8, 8)); }
public final WritableRaster createCompatibleDestRaster(Raster pSrc, IndexColorModel pIndexColorModel) { /* return new BufferedImage(pSrc.getWidth(), pSrc.getHeight(), BufferedImage.TYPE_BYTE_INDEXED, pIndexColorModel).getRaster(); */ return pIndexColorModel.createCompatibleWritableRaster(pSrc.getWidth(), pSrc.getHeight()); }
public static void main(String... args) throws IOException { int w = 30, h = 30; // create the binary mapping byte BLACK = (byte)0, WHITE = (byte)255; byte[] map = {BLACK, WHITE}; IndexColorModel icm = new IndexColorModel(1, map.length, map, map, map); // create checkered data int[] data = new int[w*h]; for(int i=0; i<w; i++) for(int j=0; j<h; j++) data[i*h + j] = i%4<2 && j%4<2 || i%4>=2 && j%4>=2 ? BLACK:WHITE; // create image from color model and data WritableRaster raster = icm.createCompatibleWritableRaster(w, h); raster.setPixels(0, 0, w, h, data); BufferedImage bi = new BufferedImage(icm, raster, false, null); // output to a file ImageIO.write(bi, "jpg", new File("C:\\Users\\user\\Desktop\\test.jpg")); }
public WritableRaster createCompatibleDestRaster(Raster src) { return icm.createCompatibleWritableRaster(src .getWidth(), src.getHeight()).createWritableTranslatedChild(src.getMinX(), src.getMinY()); }
protected SampleModel getIndexSampleModel() { if (sampleModel==null) { IndexColorModel icm = getDefaultColorModel(); WritableRaster wr = icm.createCompatibleWritableRaster(1, 1); sampleModel = wr.getSampleModel(); sampleModel = sampleModel.createCompatibleSampleModel(width, height); } return sampleModel; }
static public final BufferedImage createGrayImage(final byte[] pixels, final int width, final int height) { WritableRaster wr = Loader.GRAY_LUT.createCompatibleWritableRaster(1, 1); SampleModel sm = wr.getSampleModel().createCompatibleSampleModel(width, height); DataBuffer db = new DataBufferByte(pixels, width*height, 0); WritableRaster raster = Raster.createWritableRaster(sm, db, null); return new BufferedImage(Loader.GRAY_LUT, raster, false, null); }
protected SampleModel getIndexSampleModel() { if (sampleModel==null) { IndexColorModel icm = getDefaultColorModel(); WritableRaster wr = icm.createCompatibleWritableRaster(1, 1); sampleModel = wr.getSampleModel(); sampleModel = sampleModel.createCompatibleSampleModel(width, height); } return sampleModel; }
BufferedImage createPaletteImage(final BMHDChunk header, boolean isEHB) throws IIOException { // Create a 1 x colors.length image IndexColorModel cm = getIndexColorModel(header, isEHB); WritableRaster raster = cm.createCompatibleWritableRaster(cm.getMapSize(), 1); byte[] pixel = null; for (int x = 0; x < cm.getMapSize(); x++) { pixel = (byte[]) cm.getDataElements(cm.getRGB(x), pixel); raster.setDataElements(x, 0, pixel); } return new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null); }