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))));
}
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();
}
}
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;
}
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;
}
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);
}
Aggregations