Search in sources :

Example 21 with WritableImage

use of javafx.scene.image.WritableImage in project org.csstudio.display.builder by kasemir.

the class ColorMapDialog method updateColorBar.

/**
 * Update color bar in UI from current 'map'
 */
private void updateColorBar() {
    // On Mac OS X it was OK to create an image sized 256 x 1:
    // 256 wide to easily set the 256 colors,
    // 1 pixel height which is then stretched via the BackgroundSize().
    // On Linux, the result was garbled unless the image height matched the
    // actual height, so it's now fixed to COLOR_BAR_HEIGHT
    final WritableImage colors = new WritableImage(256, COLOR_BAR_HEIGHT);
    final PixelWriter writer = colors.getPixelWriter();
    for (int x = 0; x < 256; ++x) {
        final int arfb = ColorMappingFunction.getRGB(map.getColor(x));
        for (int y = 0; y < COLOR_BAR_HEIGHT; ++y) writer.setArgb(x, y, arfb);
    }
    // Stretch image to fill color_bar
    color_bar.setBackground(new Background(new BackgroundImage(colors, BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.DEFAULT, new BackgroundSize(BackgroundSize.AUTO, BackgroundSize.AUTO, true, true, true, true))));
}
Also used : WritableImage(javafx.scene.image.WritableImage) BackgroundImage(javafx.scene.layout.BackgroundImage) BackgroundSize(javafx.scene.layout.BackgroundSize) Background(javafx.scene.layout.Background) PixelWriter(javafx.scene.image.PixelWriter)

Example 22 with WritableImage

use of javafx.scene.image.WritableImage in project org.csstudio.display.builder by kasemir.

the class Canvas4 method thread_main.

private void thread_main() {
    final Semaphore done = new Semaphore(0);
    int to_refresh = 1;
    try {
        final BufferedImage buf = new BufferedImage((int) canvas.getWidth(), (int) canvas.getHeight(), BufferedImage.TYPE_INT_RGB);
        final WritableImage image = new WritableImage((int) canvas.getWidth(), (int) canvas.getHeight());
        while (true) {
            // Prepare AWT image
            long start = System.currentTimeMillis();
            DemoHelper.refresh(buf);
            long ms = System.currentTimeMillis() - start;
            if (draw_ms < 0)
                draw_ms = ms;
            else
                draw_ms = (draw_ms * 9 + ms) / 10;
            counter.incrementAndGet();
            // Draw into Canvas on UI thread
            start = System.currentTimeMillis();
            Platform.runLater(() -> {
                SwingFXUtils.toFXImage(buf, image);
                canvas.getGraphicsContext2D().drawImage(image, 0, 0);
                updates.setText(Long.toString(counter.get()));
                done.release();
            });
            // Wait for UI thread
            done.acquire();
            ms = System.currentTimeMillis() - start;
            if (update_ms < 0)
                update_ms = ms;
            else
                update_ms = (update_ms * 9 + ms) / 10;
            to_refresh = 1 - to_refresh;
            Thread.sleep(20);
            if ((counter.get() % 50) == 0) {
                System.out.println("Drawing: " + draw_ms + " ms");
                System.out.println("Update : " + update_ms + " ms");
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : WritableImage(javafx.scene.image.WritableImage) Semaphore(java.util.concurrent.Semaphore) BufferedImage(java.awt.image.BufferedImage)

Example 23 with WritableImage

use of javafx.scene.image.WritableImage in project CCEmuX by CCEmuX.

the class JFXTerminalFont method generateCharImage.

public Image generateCharImage(char c, Color color) {
    val coords = getCharCoords(c);
    val out = new WritableImage(coords.width, coords.height);
    val reader = base.getPixelReader();
    val writer = out.getPixelWriter();
    // TODO: probably faster to use a PixelFormat
    for (int x = 0; x < coords.width; x++) {
        for (int y = 0; y < coords.height; y++) {
            Color oc = reader.getColor(coords.x + x, coords.y + y);
            writer.setColor(x, y, Color.color(oc.getRed() * color.getRed(), oc.getGreen() * color.getGreen(), oc.getBlue() * color.getBlue(), oc.getOpacity()));
        }
    }
    return out;
}
Also used : lombok.val(lombok.val) WritableImage(javafx.scene.image.WritableImage) Color(javafx.scene.paint.Color)

Example 24 with WritableImage

use of javafx.scene.image.WritableImage in project CapsLock by chrootRISCassembler.

the class CharPanelGenerator method generate.

/**
 * Generates a panel image form char.
 * <p>First, this function converts ch to upper case if ch is lower case.</p>
 * <p>Then, this generates javafx's image from ch.And return it.</p>
 * You can fix the resolution of image through {@link capslock.CharPanelGenerator#PANEL_IMAGE_SIZE}
 * and {@link capslock.CharPanelGenerator#FONT_SIZE}.
 * @param ch パネルの生成に使う1文字.
 * @param color 背景色.
 * @return 生成されたパネル.
 */
static final Image generate(char ch, Color color) {
    final Label label = new Label(Character.toString(Character.toUpperCase(ch)));
    label.setMinSize(PANEL_IMAGE_SIZE, PANEL_IMAGE_SIZE);
    label.setMaxSize(PANEL_IMAGE_SIZE, PANEL_IMAGE_SIZE);
    label.setPrefSize(PANEL_IMAGE_SIZE, PANEL_IMAGE_SIZE);
    label.setFont(Font.font(FONT_SIZE));
    label.setAlignment(Pos.CENTER);
    label.setTextFill(Color.WHITE);
    label.setBackground(new Background(new BackgroundFill(color, CornerRadii.EMPTY, Insets.EMPTY)));
    final Scene scene = new Scene(new Group(label));
    final WritableImage img = new WritableImage(PANEL_IMAGE_SIZE, PANEL_IMAGE_SIZE);
    scene.snapshot(img);
    return img;
}
Also used : Group(javafx.scene.Group) WritableImage(javafx.scene.image.WritableImage) Background(javafx.scene.layout.Background) BackgroundFill(javafx.scene.layout.BackgroundFill) Label(javafx.scene.control.Label) Scene(javafx.scene.Scene)

Example 25 with WritableImage

use of javafx.scene.image.WritableImage in project latexdraw by arnobl.

the class HelperTest method assertNotEqualsSnapshot.

default <T extends Node> void assertNotEqualsSnapshot(final T node, final Runnable toExecBetweenSnap) {
    Bounds bounds = node.getBoundsInLocal();
    final SnapshotParameters params = new SnapshotParameters();
    final WritableImage oracle = new WritableImage((int) bounds.getWidth(), (int) bounds.getHeight());
    Platform.runLater(() -> node.snapshot(params, oracle));
    WaitForAsyncUtils.waitForFxEvents();
    if (toExecBetweenSnap != null) {
        toExecBetweenSnap.run();
    }
    bounds = node.getBoundsInLocal();
    final WritableImage observ = new WritableImage((int) bounds.getWidth(), (int) bounds.getHeight());
    Platform.runLater(() -> node.snapshot(params, observ));
    WaitForAsyncUtils.waitForFxEvents();
    assertNotEquals("The two snapshots do not differ.", 100d, computeSnapshotSimilarity(oracle, observ), 0.001);
}
Also used : WritableImage(javafx.scene.image.WritableImage) SnapshotParameters(javafx.scene.SnapshotParameters) Bounds(javafx.geometry.Bounds)

Aggregations

WritableImage (javafx.scene.image.WritableImage)70 SnapshotParameters (javafx.scene.SnapshotParameters)24 PixelWriter (javafx.scene.image.PixelWriter)21 PixelReader (javafx.scene.image.PixelReader)13 IOException (java.io.IOException)12 Color (javafx.scene.paint.Color)11 BufferedImage (java.awt.image.BufferedImage)9 File (java.io.File)8 Image (javafx.scene.image.Image)6 ImageView (javafx.scene.image.ImageView)6 Group (javafx.scene.Group)5 Random (java.util.Random)4 Canvas (javafx.scene.canvas.Canvas)4 GraphicsContext (javafx.scene.canvas.GraphicsContext)4 Texture (com.almasb.fxgl.texture.Texture)3 OutputStream (java.io.OutputStream)3 Point2D (javafx.geometry.Point2D)3 Scene (javafx.scene.Scene)3 Background (javafx.scene.layout.Background)3 Scale (javafx.scene.transform.Scale)3