private float[] getTextureLocation(int pixelIndex) { int scaledWidth = (int) colorPalette.getWidth() / pixelSize; int scaledHeight = (int) colorPalette.getHeight() / pixelSize; float x = (float) (Math.floorMod(pixelIndex, scaledWidth)) / (float) scaledWidth; x += 0.5f * (float) pixelSize / (float) colorPalette.getWidth(); float y = (float) (Math.floorDiv(pixelIndex, scaledWidth)) / (float) scaledHeight; y += 0.5f * (float) pixelSize / (float) colorPalette.getHeight(); return new float[] {x, y}; }
private float[] getTextureLocation(int pixelIndex) { int scaledWidth = (int) colorPalette.getWidth() / pixelSize; int scaledHeight = (int) colorPalette.getHeight() / pixelSize; float x = (float) (Math.floorMod(pixelIndex, scaledWidth)) / (float) scaledWidth; x += 0.5f * (float) pixelSize / (float) colorPalette.getWidth(); float y = (float) (Math.floorDiv(pixelIndex, scaledWidth)) / (float) scaledHeight; y += 0.5f * (float) pixelSize / (float) colorPalette.getHeight(); return new float[] {x, y}; }
public static void setRGB(WritableImage image, int[] rgb) { setRGB(image, 0, 0, (int) image.getWidth(), (int) image.getHeight(), rgb); }
/** * This method will attempt to load the given svgImage URL into the provided {@link WritableImage}, * with the SVG scaled to fit the size of the WritableImage. * * @param svgImage The image to load. * @param outputImage The location to write the loaded image once it has been rendered (it will not * happen synchronously). * @throws NullPointerException The outputImage argument must be non-null. */ public void loadSVGImage(final URL svgImage, final WritableImage outputImage) { if (outputImage == null) { throw new NullPointerException("outputImage can not be null"); //$NON-NLS-1$ } final double w = outputImage.getWidth(); final double h = outputImage.getHeight(); loadSVGImage(svgImage, w, h, null, outputImage); }
/** * This method will attempt to load the given svgImage URL into the provided * {@link WritableImage}, with the SVG scaled to fit the size of the * WritableImage. * * @param svgImage The image to load. * @param outputImage The location to write the loaded image once it has * been rendered (it will not happen synchronously). * @throws NullPointerException The outputImage argument must be non-null. */ public static void loadSVGImage(final URL svgImage, final WritableImage outputImage) { if (outputImage == null) { throw new NullPointerException("outputImage can not be null"); //$NON-NLS-1$ } final double w = outputImage.getWidth(); final double h = outputImage.getHeight(); loadSVGImage(svgImage, w, h, null, outputImage); }
Platform.runLater(new Runnable() { @Override public void run() { Text text = new Text("TEST"); text.setFill(Color.RED); WritableImage image = text.snapshot(new SnapshotParameters(), null); double imageVPos = (getHeight() - image.getHeight()) / 2; BackgroundImage backImage = new BackgroundImage( image, BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, new BackgroundPosition(Side.LEFT, 7D, false, Side.TOP, imageVPos, false), new BackgroundSize(image.getWidth(), image.getHeight(), false, false, false, false)); List<BackgroundImage> images = new ArrayList<BackgroundImage>(); images.add(backImage); setBackground(new Background(getBackground().getFills(), images)); } });
public void start(Stage primaryStage) { Group mainGroup = new Group(); Rectangle r = new Rectangle(0, 0, 200, 200); Stop[] stops = new Stop[] { new Stop(0, new Color(0.0, 0.0, 1.0, 1.0)), new Stop(1, new Color(1.0, 1.0, 1.0, 0.0)) }; LinearGradient lg = new LinearGradient(0, 0, 1, 1, true, CycleMethod.NO_CYCLE, stops); r.setFill(lg); mainGroup.getChildren().add(r); Scene scene = new Scene(mainGroup, 200, 200); scene.setFill(Color.TRANSPARENT); primaryStage.setScene(scene); primaryStage.show(); WritableImage image = scene.snapshot(null); PixelReader pixelReader = image.getPixelReader(); System.out.println("Color: " + pixelReader.getColor((int)image.getWidth()/2, (int)image.getHeight()/2)); }
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); } } }
final int h = bimg.getHeight(); if (wimg == null || wimg.getWidth() != w || wimg.getHeight() != h) { wimg = new WritableImage(bimg.getWidth(), bimg.getHeight());
int width = target.getWidth(); int height = target.getHeight();
private void interpolate(WritableImage img) { CalculationGrid calculationGrid = new CalculationGrid((int) img.getWidth(), (int) img.getHeight(), serializedRaster); NineAvgInterpolationOperator operator = new NineAvgInterpolationOperator(); operator.execute(calculationGrid); serializedRaster = calculationGrid.getValues(); renderImage(img); }
int width = (int) target.getWidth(); int height = (int) target.getHeight();
PixelReader imageReader = srcImage.getPixelReader(); int width = (int) srcMask.getWidth(); int height = (int) srcMask.getHeight();
int w = (int)snapshot.getWidth(); int h = (int)snapshot.getHeight();
for (int ty = ty0 * zoomFactor; ty < ty0 * zoomFactor + zoomFactor; ty++) { if (tx < zoomImage.getWidth() && ty < zoomImage.getHeight()) zoomImage.getPixelWriter().setColor(tx, ty, color);
@Override public void loadPixels() { if ((pixels == null) || (pixels.length != pixelWidth * pixelHeight)) { pixels = new int[pixelWidth * pixelHeight]; loaded = false; } if (!loaded) { if (snapshotImage == null || snapshotImage.getWidth() != pixelWidth || snapshotImage.getHeight() != pixelHeight) { snapshotImage = new WritableImage(pixelWidth, pixelHeight); } SnapshotParameters sp = null; if (pixelDensity != 1) { sp = new SnapshotParameters(); sp.setTransform(Transform.scale(pixelDensity, pixelDensity)); } snapshotImage = ((PSurfaceFX) surface).canvas.snapshot(sp, snapshotImage); PixelReader pr = snapshotImage.getPixelReader(); pr.getPixels(0, 0, pixelWidth, pixelHeight, argbFormat, pixels, 0, pixelWidth); loaded = true; modified = false; } }
if (who.pixelWidth != cash.image.getWidth() || who.pixelHeight != cash.image.getHeight()) { cash = null;
snapshotImage.getWidth() != pixelWidth || snapshotImage.getHeight() != pixelHeight) { snapshotImage = new WritableImage(pixelWidth, pixelHeight);