private Image getHuesCircle(int width, int height) { WritableImage raster = new WritableImage(width, height); PixelWriter pixelWriter = raster.getPixelWriter(); Point2D center = new Point2D((double) width / 2, (double) height / 2); double rsmall = 0.8 * width / 2; double rbig = (double) width / 2; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { double dx = x - center.getX(); double dy = y - center.getY(); double distance = Math.sqrt((dx * dx) + (dy * dy)); double o = Math.atan2(dy, dx); if (distance > rsmall && distance < rbig) { double H = map(o, -Math.PI, Math.PI, 0, 255); double S = 255; double L = 152; pixelWriter.setColor(x, y, HSL2RGB(H, S, L)); } } } return raster; }
private Image getSLCricle(int width, int height) { WritableImage raster = new WritableImage(width, height); PixelWriter pixelWriter = raster.getPixelWriter(); Point2D center = new Point2D((double) width / 2, (double) height / 2); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { double dy = x - center.getX(); double dx = y - center.getY(); pixelWriter.setColor(x, y, getColor(dx, dy)); } } return raster; }
GraphicsContext gc = canvas.getGraphicsContext2D(); PixelWriter pixelWriter = gc.getPixelWriter(); pixelWriter.setColor( 75, 100, Color.FORESTGREEN );
public static Image colorPallete(int numColors){ int width=(int)Math.sqrt(numColors); int height=numColors/width; WritableImage img = new WritableImage(width, height); PixelWriter pw = img.getPixelWriter(); AtomicInteger count = new AtomicInteger(); IntStream.range(0, height).boxed() .forEach(y->IntStream.range(0, width).boxed() .forEach(x->pw.setColor(x, y, getColor(count.getAndIncrement(),numColors)))); // save for testing purposes try { ImageIO.write(SwingFXUtils.fromFXImage(img, null), "jpg", new File("palette.jpg")); } catch (IOException ex) { } return img; } private Color getColor(int iColor, int numColors){ // nice palette of colors java.awt.Color c = java.awt.Color.getHSBColor((float) iColor / (float) numColors, 1.0f, 1.0f); return Color.rgb(c.getRed(), c.getGreen(), c.getBlue()); // raw palette //return Color.rgb((iColor >> 16) & 0xFF, (iColor >> 8) & 0xFF, iColor & 0xFF); }
public class ImageRenderer { public void render(GraphicsContext context, Image image, int sx, int sy, int sw, int sh, int tx, int ty) { PixelReader reader = image.getPixelReader(); PixelWriter writer = context.getPixelWriter(); for (int x = 0; x < sw; x++) { for (int y = 0; y < sh; y++) { Color color = reader.getColor(sx + x, sy + y); if (color.isOpaque()) { writer.setColor(tx + x, ty + y, color); } } } } }
private void renderImage(WritableImage img) { PixelWriter pw = img.getPixelWriter(); double w = img.getWidth(); double h = img.getHeight(); for (int ih = 0; ih < h; ih++) { for (int iw = 0; iw < w; iw++) { int value = (serializedRaster == null) ? Integer.MIN_VALUE : serializedRaster[ih * (int) w + iw]; // hue = Math.sin(yRatio*(gridSize*Math.PI))*Math.sin(xRatio*(gridSize*Math.PI))*Math.tan(hueFactor/20.0)*360.0 + hueOffset; // Color c = Color.hsb(hue, 1.0, 1.0); // Color black = Color.BLACK; // Color red = Color.RED; // Color c = (value == Integer.MIN_VALUE) ? red : black; java.awt.Color awtc = palette.getColorForValue(value); Color c = Color.rgb(awtc.getRed(), awtc.getGreen(), awtc.getBlue()); pw.setColor(iw, ih, c); } } }
private void writePixel(int pixelIndex, Color color) { int width = (int) colorPalette.getRequestedWidth(); int xStart = Math.floorMod(pixelIndex * pixelSize, width); int yStart = Math.floorDiv(pixelIndex * pixelSize, width) * pixelSize; for (int x = xStart; x < xStart + pixelSize; x++) { for (int y = yStart; y < yStart + pixelSize; y++) { colorPalette.getPixelWriter().setColor(x, y, color); } } }
private void updateColorPalette() { int width = hueResolution != -1 ? hueResolution : saturationResolution; int height = brightnessResolution != -1 ? brightnessResolution : saturationResolution; WritableImage image = new WritableImage(width, height); PixelWriter pw = image.getPixelWriter(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pw.setColor(x, y, getColorAtLocation(x, y)); } } if (PRINT_PALETTE) { // save for testing purposes try { ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", new File("palette.png")); } catch (IOException ex) { } } colorPalette = image; }
private void writePixel(int pixelIndex, Color color) { int width = (int) colorPalette.getRequestedWidth(); int xStart = Math.floorMod(pixelIndex * pixelSize, width); int yStart = Math.floorDiv(pixelIndex * pixelSize, width) * pixelSize; for (int x = xStart; x < xStart + pixelSize; x++) { for (int y = yStart; y < yStart + pixelSize; y++) { colorPalette.getPixelWriter().setColor(x, y, color); } } }
private void updateColorPalette() { int width = hueResolution != -1 ? hueResolution : saturationResolution; int height = brightnessResolution != -1 ? brightnessResolution : saturationResolution; WritableImage image = new WritableImage(width, height); PixelWriter pw = image.getPixelWriter(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pw.setColor(x, y, getColorAtLocation(x, y)); } } if (PRINT_PALETTE) { // save for testing purposes try { ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", new File("palette.png")); } catch (IOException ex) { } } colorPalette = image; }
pw.setColor(x, y, getColorAtIndex(x));
pw.setColor(x, y, getColorAtIndex(x));
private Image getHuesCircle(int width, int height) { WritableImage raster = new WritableImage(width, height); PixelWriter pixelWriter = raster.getPixelWriter(); Point2D center = new Point2D((double) width / 2, (double) height / 2); double rsmall = 0.8 * width / 2; double rbig = (double) width / 2; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { double dx = x - center.getX(); double dy = y - center.getY(); double distance = Math.sqrt((dx * dx) + (dy * dy)); double o = Math.atan2(dy, dx); if (distance > rsmall && distance < rbig) { double H = map(o, -Math.PI, Math.PI, 0, 255); double S = 255; double L = 152; pixelWriter.setColor(x, y, HSL2RGB(H, S, L)); } } } return raster; }
private Image getSLCricle(int width, int height) { WritableImage raster = new WritableImage(width, height); PixelWriter pixelWriter = raster.getPixelWriter(); Point2D center = new Point2D((double) width / 2, (double) height / 2); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { double dy = x - center.getX(); double dx = y - center.getY(); pixelWriter.setColor(x, y, getColor(dx, dy)); } } return raster; }
/** * copy the given image to a writeable image * * @param image * @return a writable image */ public static WritableImage copyImage(Image image) { int height = (int) image.getHeight(); int width = (int) image.getWidth(); PixelReader pixelReader = image.getPixelReader(); WritableImage writableImage = new WritableImage(width, height); PixelWriter pixelWriter = writableImage.getPixelWriter(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { Color color = pixelReader.getColor(x, y); pixelWriter.setColor(x, y, color); } } return writableImage; }
+ zoomFactor; ty++) { if (tx < zoomImage.getWidth() && ty < zoomImage.getHeight()) zoomImage.getPixelWriter().setColor(tx, ty, color);
/** * get the Image for the given composite and color map * * @param displayContext */ public static void getImageContent(DisplayContext displayContext) { RadarImage c = displayContext.composite; FloatFunction<Color> colorMap = displayContext.heatmap; int width = c.getGridWidth(); int height = c.getGridHeight(); WritableImage img = displayContext.mapView.getWriteableImage(); if (img == null) return; PixelWriter pw = img.getPixelWriter(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float value = c.getValue(x, y); Color color = colorMap.apply(value); pw.setColor(x, y, color); } } }