use of javafx.scene.image.WritableImage in project jphp by jphp-compiler.
the class UXCanvas method save.
@Signature
public void save(Environment env, Memory stream, String format) throws IOException, InvocationTargetException, InterruptedException {
SnapshotParameters param = new SnapshotParameters();
param.setDepthBuffer(true);
param.setFill(javafx.scene.paint.Color.TRANSPARENT);
try {
final WritableImage image = getWrappedObject().snapshot(param, null);
BufferedImage bImage = SwingFXUtils.fromFXImage(image, null);
try {
OutputStream out = Stream.getOutputStream(env, stream);
if (out == null) {
throw new IOException();
}
try {
ImageIO.write(bImage, format, out);
} finally {
Stream.closeStream(env, out);
}
} catch (IOException e) {
env.wrapThrow(e);
}
} catch (IllegalArgumentException e) {
;
}
}
use of javafx.scene.image.WritableImage in project jphp by jphp-compiler.
the class UXNode method snapshot.
@Signature
public UXImage snapshot(Environment env) {
SnapshotParameters snapParams = new SnapshotParameters();
snapParams.setFill(Color.TRANSPARENT);
WritableImage snapshot = getWrappedObject().snapshot(snapParams, null);
return snapshot == null ? null : new UXImage(env, snapshot);
}
use of javafx.scene.image.WritableImage in project jphp by jphp-compiler.
the class ImageViewEx method update.
protected void update() {
if (autoSize) {
setWidth(image == null ? 0 : image.getWidth());
setHeight(image == null ? 0 : image.getHeight());
}
g2.clearRect(0, 0, getWidth(), getHeight());
if (background != null) {
g2.setFill(background);
g2.fillRect(0, 0, getWidth(), getHeight());
}
if (image != null) {
double x = 0, y = 0, w = image.getWidth(), h = image.getHeight();
if (isMosaic()) {
int horCount = (int) Math.ceil(getWidth() / w + mosaicGap);
int verCount = (int) Math.ceil(getHeight() / h + mosaicGap);
int startX = 0;
int startY = 0;
for (int i = startY; i < verCount; i++) {
for (int j = startX; j < horCount; j++) {
g2.drawImage(image, j * w + (j * mosaicGap), i * h + (i * mosaicGap), w, h);
}
}
} else {
if (isStretch()) {
if (!smartStretch || (w > getWidth() || h > getHeight())) {
if (isProportional()) {
double ratio = Math.min(getWidth() / w, getHeight() / h);
w = (int) (w * ratio);
h = (int) (h * ratio);
} else {
w = getWidth();
h = getHeight();
}
}
}
if (isCentered()) {
x = Math.round(getWidth() / 2 - w / 2);
y = Math.round(getHeight() / 2 - h / 2);
}
if (isStretch() && (flipX || flipY)) {
Canvas canvas = new Canvas();
canvas.setWidth(w);
canvas.setHeight(h);
GraphicsContext g2_tmp = canvas.getGraphicsContext2D();
g2_tmp.drawImage(image, x, y, w, h);
SnapshotParameters snapshotParameters = new SnapshotParameters();
snapshotParameters.setFill(Color.TRANSPARENT);
WritableImage snapshot = canvas.snapshot(snapshotParameters, null);
g2.drawImage(snapshot, x, y, w, h, flipX ? w : 0, flipY ? h : 0, w * (flipX ? -1 : 1), h * (flipY ? -1 : 1));
} else {
if (flipX || flipY) {
g2.drawImage(image, x, y, w, h, flipX ? w : 0, flipY ? h : 0, w * (flipX ? -1 : 1), h * (flipY ? -1 : 1));
} else {
g2.drawImage(image, x, y, w, h);
}
}
}
}
if (text != null && !text.trim().isEmpty()) {
g2.setFont(font);
g2.setFill(textFill);
double fWidth = UXFont.calculateTextWidth(text, font);
double fHeight = UXFont.getLineHeight(font);
g2.fillText(text, getWidth() / 2 - fWidth / 2, getHeight() / 2 + fHeight / 4, getWidth());
}
}
use of javafx.scene.image.WritableImage in project jphp by jphp-compiler.
the class DnDTabPaneSkin method tabPane_handleDragStart.
void tabPane_handleDragStart(MouseEvent event) {
try {
// $NON-NLS-1$
Field f_tab = event.getSource().getClass().getDeclaredField("tab");
f_tab.setAccessible(true);
Tab t = (Tab) f_tab.get(event.getSource());
if (t != null && efx_canStartDrag(t)) {
DRAGGED_TAB = t;
Node node = (Node) event.getSource();
Dragboard db = node.startDragAndDrop(TransferMode.MOVE);
WritableImage snapShot = node.snapshot(new SnapshotParameters(), null);
PixelReader reader = snapShot.getPixelReader();
int padX = 10;
int padY = 10;
int width = (int) snapShot.getWidth();
int height = (int) snapShot.getHeight();
WritableImage image = new WritableImage(width + padX, height + padY);
PixelWriter writer = image.getPixelWriter();
int h = 0;
int v = 0;
while (h < width + padX) {
v = 0;
while (v < height + padY) {
if (h >= padX && h <= width + padX && v >= padY && v <= height + padY) {
writer.setColor(h, v, reader.getColor(h - padX, v - padY));
} else {
writer.setColor(h, v, Color.TRANSPARENT);
}
v++;
}
h++;
}
db.setDragView(image, image.getWidth(), image.getHeight() * -1);
ClipboardContent content = new ClipboardContent();
String data = efx_getClipboardContent(t);
if (data != null) {
content.put(TAB_MOVE, data);
}
db.setContent(content);
}
} catch (Throwable t) {
// // TODO Auto-generated catch block
t.printStackTrace();
}
}
use of javafx.scene.image.WritableImage in project JFoenix by jfoenixadmin.
the class ExtendedAnimatedFlowContainer method updatePlaceholder.
private void updatePlaceholder(Node newView) {
if (view.getWidth() > 0 && view.getHeight() > 0) {
SnapshotParameters parameters = new SnapshotParameters();
parameters.setFill(Color.TRANSPARENT);
Image placeholderImage = view.snapshot(parameters, new WritableImage((int) view.getWidth(), (int) view.getHeight()));
placeholder.setImage(placeholderImage);
placeholder.setFitWidth(placeholderImage.getWidth());
placeholder.setFitHeight(placeholderImage.getHeight());
} else {
placeholder.setImage(null);
}
placeholder.setVisible(true);
placeholder.setOpacity(1.0);
view.getChildren().setAll(placeholder, newView);
placeholder.toFront();
}
Aggregations