private BufferedImage createBufferedImage(final int width, final int height, final int imageType) { BufferedImage image = new BufferedImage(width, height, imageType); WritableRaster raster = image.getRaster(); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { raster.setSample(j, i, 0, 50); } } return image; } }
case DataBuffer.TYPE_DOUBLE: raster.setSample(x, y, dstBand, it.getDoubleNext()); break; raster.setSample(x, y, dstBand, it.getFloatNext()); break; raster.setSample(x, y, dstBand, b); break; raster.setSample(x, y, dstBand, it.getIntNext()); break; for (int y = ymin; y < ymax; y++) { for (int x = xmin; x < xmax; x++) { raster.setSample(x, y, dstBand, it.getIntNext());
raster.setSample(x, y, 0, v);
/** * Sets the buffered image to a raster filled with random value using the specified random * number generator. This method can be used for testing purpose, or for adding noise to a * coverage. */ public void setBufferedImage(final Random random) { image = null; // Will forces the creation of a new BufferedImage. final BufferedImage image = getBufferedImage(); final WritableRaster raster = image.getRaster(); final ColorModel model = image.getColorModel(); final int size; if (model instanceof IndexColorModel) { size = ((IndexColorModel) model).getMapSize(); } else { size = 1 << Short.SIZE; } for (int i = raster.getWidth(); --i >= 0; ) { for (int j = raster.getHeight(); --j >= 0; ) { raster.setSample(i, j, 0, random.nextInt(size)); } } }
/** * Creates a simple 500x500 {@link RenderedImage} for testing purposes. * * <p>Values are randomly set to the provided noDataValue. * * @param noDataValue * @return */ public static RenderedImage getSynthetic(final double noDataValue) { final int width = 500; final int height = 500; final WritableRaster raster = RasterFactory.createBandedRaster(DataBuffer.TYPE_DOUBLE, width, height, 1, null); final Random random = new Random(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (random.nextFloat() > 0.9) raster.setSample(x, y, 0, noDataValue); else raster.setSample(x, y, 0, (x + y)); } } final ColorModel cm = new ComponentColorModelJAI( ColorSpace.getInstance(ColorSpace.CS_GRAY), false, false, Transparency.OPAQUE, DataBuffer.TYPE_DOUBLE); final BufferedImage image = new BufferedImage(cm, raster, false, null); return image; }
/** * Building a synthetic image upon a FLOAT sample-model. * * @return {@linkplain BufferedImage} */ private BufferedImage getSynthetic_Float() { final int width = 500; final int height = 500; final WritableRaster raster = RasterFactory.createBandedRaster(DataBuffer.TYPE_FLOAT, width, height, 1, null); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { raster.setSample(x, y, 0, (x + y)); } } final ColorModel cm = new ComponentColorModelJAI( ColorSpace.getInstance(ColorSpace.CS_GRAY), false, false, Transparency.OPAQUE, DataBuffer.TYPE_FLOAT); final BufferedImage image = new BufferedImage(cm, raster, false, null); return image; }
/** * Synthetic with Float Sample Model! * * @return {@linkplain BufferedImage} */ private BufferedImage getSynthetic_Double() { final int width = 500; final int height = 500; final WritableRaster raster = RasterFactory.createBandedRaster(DataBuffer.TYPE_DOUBLE, width, height, 1, null); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { raster.setSample(x, y, 0, (x + y)); } } final ColorModel cm = new ComponentColorModelJAI( ColorSpace.getInstance(ColorSpace.CS_GRAY), false, false, Transparency.OPAQUE, DataBuffer.TYPE_DOUBLE); final BufferedImage image = new BufferedImage(cm, raster, false, null); return image; }
r.getPixel(i, j, rgba); destWr.setSample(ii, jj, 0, findColorIndex(root, rgba, alphaBand));
WritableRaster raster = image.getRaster(); for(int h=0;h<height;h++) { for(int w=0;w<width;w++) { int colour = 127; raster.setSample(w,h,0,colour); } }
raster.setSample(x, y, 0, value); for (int x = 0; x < activeCols; x++) { float value = (float) rasterByteBuffer.getDouble(); raster.setSample(x, y, 0, value); for (int x = 0; x < activeCols; x++) { float value = rasterByteBuffer.getFloat(); raster.setSample(x, y, 0, value); value = noData.intValue(); raster.setSample(x, y, 0, value);
for (int dy = bounds.y, drow = 0; drow < bounds.height; dy++, drow++) { for (int dx = bounds.x, dcol = 0; dcol < bounds.width; dx++, dcol++, k++) { destTile.setSample(dx, dy, 0, Float.intBitsToFloat(data[k]));
for (int j = miny; j < maxy; j++) { sourceRaster.getPixel(i, j, rgba); destRaster.setSample( i, j, 0, paletteBuilder.findNearestColorIndex(rgba, alphaBand));
public static void main(String... args) throws IOException { int w = 40, h = 40, divs = 5; BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_GRAY); WritableRaster raster = bi.getRaster(); for(int i=0; i<w; i++) for(int j=0; j<h; j++) raster.setSample(i,j,0,128+(int)(127*Math.sin(Math.PI*i/w*divs)*Math.sin(Math.PI*j/h*divs))); ImageIO.write(bi, "jpg", new File("C:\\Users\\user\\Desktop\\test.jpg")); }
public void setRasterValue(Coordinate coordinate, int value) { checkState(); if (!boundingBox.contains(coordinate.x, coordinate.y)) { throw new IllegalArgumentException("Can only add raster values for coordinates (" + coordinate + ") within the bounding box (" + boundingBox + ")"); } Point p = this.gridCellSize.getCell(boundingBox, coordinate); LOGGER.log(Level.FINEST, "raster value set to {0} on cell {1}", new Object[]{value, p}); this.raster.setSample(p.x, p.y, 0, value); dirty = true; }
public GridCoverage2D getDummyRaster() { WritableRaster raster = WritableRaster.createBandedRaster(DataBuffer.TYPE_INT, 1,1,1, new Point(0,0)); raster.setSample(0,0,0,Integer.MIN_VALUE); Envelope e = getActivityField().getBoundingBox().getEnvelopeInternal(); BoundingBox boundingBox = new ReferencedEnvelope(e.getMinX(), e.getMaxX(), e.getMinY(), e.getMaxY(), DefaultGeographicCRS.WGS84); GridCoverageFactory factory = CoverageFactoryFinder.getGridCoverageFactory(null); return factory.create("name", raster, boundingBox); }