Java Code Examples for javafx.scene.SnapshotParameters#setFill()

The following examples show how to use javafx.scene.SnapshotParameters#setFill() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LivePanel.java    From Quelea with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Get a preview image of the web view or move it to the main panel if it's
 * not visible.
 *
 * @return a screenshot image of the web view
 */
private Image geWebPreviewImage() {
    DisplayCanvas canvas = QueleaApp.get().getProjectionWindow().getCanvas();
    if (QueleaApp.get().getProjectionWindow().isShowing() && isContentShowing()) {
        Double d = canvas.getBoundsInLocal().getHeight();
        int h = d.intValue();
        Double d2 = canvas.getBoundsInLocal().getWidth();
        ;
        int w = d2.intValue();
        webPreviewImage = new WritableImage(w, h);
        SnapshotParameters params = new SnapshotParameters();
        params.setFill(Color.TRANSPARENT);
        canvas.snapshot(params, webPreviewImage);
        BufferedImage bi = SwingFXUtils.fromFXImage((WritableImage) webPreviewImage, null);
        SwingFXUtils.toFXImage(bi, webPreviewImage);
        WebView wv = getWebPanel().removeWebView();
        if (wv != null && !canvas.getChildren().contains(wv)) {
            canvas.getChildren().add(wv);
        }
        return webPreviewImage;
    } else {
        getWebPanel().addWebView((WebDisplayable) getDisplayable());
        return new Image("file:icons/web preview.png");
    }
}
 
Example 2
Source File: SVGDocumentGenerator.java    From latexdraw with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a thumbnail from the given selection in the given file.
 * @param templateFile The file of the future thumbnail.
 * @param selection The set of shapes composing the template.
 */
private void createTemplateThumbnail(final File templateFile, final javafx.scene.Group selection) {
	final Bounds bounds = selection.getBoundsInParent();
	final double scale = 70d / Math.max(bounds.getWidth(), bounds.getHeight());
	final WritableImage img = new WritableImage((int) (bounds.getWidth() * scale), (int) (bounds.getHeight() * scale));
	final SnapshotParameters snapshotParameters = new SnapshotParameters();

	snapshotParameters.setFill(Color.WHITE);
	snapshotParameters.setTransform(new Scale(scale, scale));
	selection.snapshot(snapshotParameters, img);

	final BufferedImage bufferedImage = SwingFXUtils.fromFXImage(img, null);

	try {
		ImageIO.write(bufferedImage, "png", templateFile);  //NON-NLS
	}catch(final IOException ex) {
		BadaboomCollector.INSTANCE.add(ex);
	}
	bufferedImage.flush();
}
 
Example 3
Source File: FxmlControl.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public static Image snap(Node node) {
    try {
        final Bounds bounds = node.getLayoutBounds();
        double scale = dpiScale();
        int imageWidth = (int) Math.round(bounds.getWidth() * scale);
        int imageHeight = (int) Math.round(bounds.getHeight() * scale);
        final SnapshotParameters snapPara = new SnapshotParameters();
        snapPara.setFill(Color.TRANSPARENT);
        snapPara.setTransform(javafx.scene.transform.Transform.scale(scale, scale));
        WritableImage snapshot = new WritableImage(imageWidth, imageHeight);
        snapshot = node.snapshot(snapPara, snapshot);
        return snapshot;
    } catch (Exception e) {
        logger.debug(e.toString());
        return null;
    }

}
 
Example 4
Source File: Tools.java    From logbook-kai with MIT License 6 votes vote down vote up
/**
 * ノードの内容をPNGファイルとして出力します
 *
 * @param node ノード
 * @param title タイトル及びファイル名
 * @param own 親ウインドウ
 */
public static void storeSnapshot(Node node, String title, Window own) {
    try {
        FileChooser chooser = new FileChooser();
        chooser.setTitle(title + "の保存");
        chooser.setInitialFileName(title + ".png");
        chooser.getExtensionFilters().addAll(
                new ExtensionFilter("PNG Files", "*.png"));
        File f = chooser.showSaveDialog(own);
        if (f != null) {
            SnapshotParameters sp = new SnapshotParameters();
            sp.setFill(Color.WHITESMOKE);
            WritableImage image = node.snapshot(sp, null);
            try (OutputStream out = Files.newOutputStream(f.toPath())) {
                ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", out);
            }
        }
    } catch (Exception e) {
        alert(AlertType.WARNING, "画像ファイルに保存出来ませんでした", "指定された場所へ画像ファイルを書き込みできませんでした", e, own);
    }
}
 
Example 5
Source File: DigitFactory.java    From metastone with GNU General Public License v2.0 6 votes vote down vote up
public static void saveAllDigits() {
	Stage stage = new Stage(StageStyle.TRANSPARENT);
	DigitTemplate root = new DigitTemplate();
	Scene scene = new Scene(root);
	stage.setScene(scene);
	stage.show();

	SnapshotParameters snapshotParams = new SnapshotParameters();
	snapshotParams.setFill(Color.TRANSPARENT);
	root.digit.setText("-");
	for (int i = 0; i <= 10; i++) {
		WritableImage image = root.digit.snapshot(snapshotParams, null);

		File file = new File("src/" + IconFactory.RESOURCE_PATH + "/img/common/digits/" + root.digit.getText() + ".png");

		try {
			ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file);
		} catch (IOException e) {
			e.printStackTrace();
		}
		root.digit.setText("" + i);
	}

	stage.close();
}
 
Example 6
Source File: AndroidPicturesService.java    From attach with GNU General Public License v3.0 5 votes vote down vote up
private static Image rotateImage(Image image, int rotate) {
    if (image == null || rotate == 0) {
        return image;
    }
    ImageView iv = new ImageView(image);
    iv.setFitWidth(1280);
    iv.setFitHeight(1280);
    iv.setPreserveRatio(true);
    iv.setRotate(rotate);
    SnapshotParameters params = new SnapshotParameters();
    params.setFill(Color.TRANSPARENT);
    return iv.snapshot(params, null);
}
 
Example 7
Source File: CachePolicy.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void cache(Pane node) {
    if (!cache.containsKey(node)) {
        SnapshotParameters snapShotparams = new SnapshotParameters();
        snapShotparams.setFill(Color.TRANSPARENT);
        WritableImage temp = node.snapshot(snapShotparams,
            new WritableImage((int) node.getLayoutBounds().getWidth(),
                (int) node.getLayoutBounds().getHeight()));
        ImageView tempImage = new ImageView(temp);
        tempImage.setCache(true);
        tempImage.setCacheHint(CacheHint.SPEED);
        cache.put(node, new ArrayList<>(node.getChildren()));
        node.getChildren().setAll(tempImage);
    }
}
 
Example 8
Source File: JFXDatePickerContent.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
protected void forward(int offset, ChronoUnit unit, boolean focusDayCell, boolean withAnimation) {
    if (withAnimation) {
        if (tempImageTransition == null || tempImageTransition.getStatus() == Status.STOPPED) {
            Pane monthContent = (Pane) calendarPlaceHolder.getChildren().get(0);
            this.getParent().setManaged(false);
            SnapshotParameters snapShotparams = new SnapshotParameters();
            snapShotparams.setFill(Color.TRANSPARENT);
            WritableImage temp = monthContent.snapshot(snapShotparams,
                new WritableImage((int) monthContent.getWidth(),
                    (int) monthContent.getHeight()));
            ImageView tempImage = new ImageView(temp);
            calendarPlaceHolder.getChildren().add(calendarPlaceHolder.getChildren().size() - 2, tempImage);
            TranslateTransition imageTransition = new TranslateTransition(Duration.millis(160), tempImage);
            imageTransition.setToX(-offset * calendarPlaceHolder.getWidth());
            imageTransition.setOnFinished((finish) -> calendarPlaceHolder.getChildren().remove(tempImage));
            monthContent.setTranslateX(offset * calendarPlaceHolder.getWidth());
            TranslateTransition contentTransition = new TranslateTransition(Duration.millis(160), monthContent);
            contentTransition.setToX(0);

            tempImageTransition = new ParallelTransition(imageTransition, contentTransition);
            tempImageTransition.setOnFinished((finish) -> {
                calendarPlaceHolder.getChildren().remove(tempImage);
                this.getParent().setManaged(true);
            });
            tempImageTransition.play();
        }
    }
    YearMonth yearMonth = selectedYearMonth.get();
    DateCell dateCell = currentFocusedDayCell;
    if (dateCell == null || !(dayCellDate(dateCell).getMonth() == yearMonth.getMonth())) {
        dateCell = findDayCellOfDate(yearMonth.atDay(1));
    }
    goToDayCell(dateCell, offset, unit, focusDayCell);
}
 
Example 9
Source File: DragAndDropHandler.java    From FxDock with Apache License 2.0 5 votes vote down vote up
protected static Image createDragImage(FxDockPane client)
{
	SnapshotParameters sp = new SnapshotParameters();
	sp.setFill(Color.TRANSPARENT);
	
	WritableImage im = client.snapshot(sp, null);

	if(client.isPaneMode())
	{
		return im;
	}
	
	// include selected tab
	FxDockTabPane tp = (FxDockTabPane)DockTools.getParent(client);
	Node n = tp.lookup(".tab:selected");
	WritableImage tim = n.snapshot(sp, null);
	
	double dy = tim.getHeight();
	
	// must adjust for the tab
	deltay += dy;
	
	double w = Math.max(im.getWidth(), tim.getWidth());
	double h = im.getHeight() + dy;
	Canvas c = new Canvas(w, h);
	GraphicsContext g = c.getGraphicsContext2D();
	g.drawImage(tim, 0, 0);
	g.drawImage(im, 0, dy);
	return c.snapshot(sp, null);
}
 
Example 10
Source File: Ships.java    From logbook-kai with MIT License 5 votes vote down vote up
/**
 * キャラクターの画像を取得します(装飾無し、バックグラウンドでのロード)
 *
 * @param chara キャラクター
 * @return 艦娘の画像
 * @throws IllegalStateException このメソッドがJavaFXアプリケーション・スレッド以外のスレッドで呼び出された場合
 */
public static Image getBackgroundLoading(Chara chara) throws IllegalStateException {
    Image img = ShipImage.getBackgroundLoading(chara);
    if (img != null) {
        return img;
    }
    Canvas canvas = new Canvas(160, 40);
    SnapshotParameters sp = new SnapshotParameters();
    sp.setFill(Color.TRANSPARENT);
    return canvas.snapshot(sp, null);
}
 
Example 11
Source File: ViewUtils.java    From ApkToolPlus with Apache License 2.0 5 votes vote down vote up
/**
 * 把一个Node导出为png图片
 *
 * @param node      节点
 * @param saveFile  图片文件
 * @return  是否导出成功
 */
public static boolean node2Png(Node node, File saveFile) {
    SnapshotParameters parameters = new SnapshotParameters();
    // 背景透明
    parameters.setFill(Color.TRANSPARENT);
    WritableImage image = node.snapshot(parameters, null);
    //probably use a file chooser here(原来这里是使用一个文件选择器)
    try {
        return ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", saveFile);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return false;
}
 
Example 12
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static Image addShadowFx(Image image, int shadow, Color color) {
        try {
            if (image == null || shadow <= 0) {
                return null;
            }
            double imageWidth = image.getWidth(), imageHeight = image.getHeight();
            Group group = new Group();
            Scene s = new Scene(group);

            ImageView view = new ImageView(image);
            view.setPreserveRatio(true);
            view.setFitWidth(imageWidth);
            view.setFitHeight(imageHeight);

            DropShadow dropShadow = new DropShadow();
            dropShadow.setOffsetX(shadow);
            dropShadow.setOffsetY(shadow);
            dropShadow.setColor(color);
            view.setEffect(dropShadow);

            group.getChildren().add(view);

            SnapshotParameters parameters = new SnapshotParameters();
            parameters.setFill(Color.TRANSPARENT);
            WritableImage newImage = group.snapshot(parameters, null);
            return newImage;
        } catch (Exception e) {
//            logger.error(e.toString());
            return null;
        }

    }
 
Example 13
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static Image addArcFx(Image image, int arc, Color bgColor) {
        try {
            if (image == null || arc <= 0) {
                return null;
            }
            Group group = new Group();
            double imageWidth = image.getWidth(), imageHeight = image.getHeight();
            Scene scene = new Scene(group);

            ImageView view = new ImageView(image);
            view.setPreserveRatio(true);
            view.setFitWidth(imageWidth);
            view.setFitHeight(imageHeight);

            Rectangle clip = new Rectangle(imageWidth, imageHeight);
            clip.setArcWidth(arc);
            clip.setArcHeight(arc);
            view.setClip(clip);

            group.getChildren().add(view);

            Blend blend = new Blend(BlendMode.SRC_OVER);
            blend.setBottomInput(new ColorInput(0, 0, imageWidth, imageHeight, bgColor));
            group.setEffect(blend);

            SnapshotParameters parameters = new SnapshotParameters();
            parameters.setFill(Color.TRANSPARENT);
            WritableImage newImage = group.snapshot(parameters, null);
            return newImage;

        } catch (Exception e) {
//            logger.error(e.toString());
            return null;
        }

    }
 
Example 14
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static Image addTextFx(Image image, String textString,
        Font font, Color color, int x, int y, float transparent, int shadow) {
    try {
        Group group = new Group();

        Text text = new Text(x, y, textString);
        text.setFill(color);
        text.setFont(font);
        if (shadow > 0) {
            DropShadow dropShadow = new DropShadow();
            dropShadow.setOffsetX(shadow);
            dropShadow.setOffsetY(shadow);
            text.setEffect(dropShadow);
        }

        group.getChildren().add(text);

        Blend blend = new Blend(BlendMode.SRC_OVER);
        blend.setBottomInput(new ImageInput(image));
        blend.setOpacity(1.0 - transparent);
        group.setEffect(blend);

        SnapshotParameters parameters = new SnapshotParameters();
        parameters.setFill(Color.TRANSPARENT);
        WritableImage newImage = group.snapshot(parameters, null);
        return newImage;
    } catch (Exception e) {
        logger.error(e.toString());
        return null;
    }
}
 
Example 15
Source File: JFXDialog.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
private void showDialog() {
    if (dialogContainer == null) {
        throw new RuntimeException("ERROR: JFXDialog container is not set!");
    }
    if (isCacheContainer()) {
        tempContent = new ArrayList<>(dialogContainer.getChildren());

        SnapshotParameters snapShotparams = new SnapshotParameters();
        snapShotparams.setFill(Color.TRANSPARENT);
        WritableImage temp = dialogContainer.snapshot(snapShotparams,
            new WritableImage((int) dialogContainer.getWidth(),
                (int) dialogContainer.getHeight()));
        ImageView tempImage = new ImageView(temp);
        tempImage.setCache(true);
        tempImage.setCacheHint(CacheHint.SPEED);
        dialogContainer.getChildren().setAll(tempImage, this);
    } else {
    	//prevent error if opening an already opened dialog
    	dialogContainer.getChildren().remove(this);
    	tempContent = null;
    	dialogContainer.getChildren().add(this);
    }

    if (animation != null) {
        animation.play();
    } else {
        setVisible(true);
        setOpacity(1);
        Event.fireEvent(JFXDialog.this, new JFXDialogEvent(JFXDialogEvent.OPENED));
    }
}
 
Example 16
Source File: Export.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @return A writable image that contains given views (not null).
 */
private @NotNull BufferedImage createRenderedImage() {
	final Group views = canvas.getViews();
	final Bounds bounds = views.getBoundsInParent();
	final double scale = 3d;
	final WritableImage img = new WritableImage((int) (bounds.getWidth() * scale), (int) (bounds.getHeight() * scale));
	final SnapshotParameters snapshotParameters = new SnapshotParameters();

	snapshotParameters.setFill(Color.WHITE);
	snapshotParameters.setTransform(new Scale(scale, scale));

	views.snapshot(snapshotParameters, img);
	return SwingFXUtils.fromFXImage(img, null);
}
 
Example 17
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static Image combineSingleColumnFx(List<Image> images) {
    if (images == null || images.isEmpty()) {
        return null;
    }
    try {
        Group group = new Group();

        double x = 0, y = 0, imageWidth, imageHeight;
        double totalWidth = 0, totalHeight = 0;

        for (Image theImage : images) {
            ImageView view = new ImageView(theImage);
            imageWidth = theImage.getWidth();
            imageHeight = theImage.getHeight();

            view.setPreserveRatio(true);
            view.setX(x);
            view.setY(y);
            view.setFitWidth(imageWidth);
            view.setFitHeight(imageHeight);

            group.getChildren().add(view);
            y += imageHeight;

            if (imageWidth > totalWidth) {
                totalWidth = imageWidth;
            }
        }
        totalHeight = y;
        Blend blend = new Blend(BlendMode.SRC_OVER);
        blend.setBottomInput(new ColorInput(0, 0, totalWidth, totalHeight, Color.TRANSPARENT));
        group.setEffect(blend);

        SnapshotParameters parameters = new SnapshotParameters();
        parameters.setFill(Color.TRANSPARENT);
        WritableImage newImage = group.snapshot(parameters, null);
        return newImage;
    } catch (Exception e) {
        logger.error(e.toString());
        return null;
    }
}
 
Example 18
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static Image combineImagesColumnFx(List<Image> images,
        Color bgColor, int interval, int Margin) {
    try {
        if (images == null || images.isEmpty()) {
            return null;
        }
        Group group = new Group();

        int x = Margin, y = Margin, width = 0, height = 0;
        for (int i = 0; i < images.size(); ++i) {
            Image image = images.get(i);
            ImageView view = new ImageView(image);
            view.setPreserveRatio(true);
            view.setFitWidth(image.getWidth());
            view.setFitHeight(image.getHeight());
            view.setX(x);
            view.setY(y);
            group.getChildren().add(view);

            x = Margin;
            y += image.getHeight() + interval;

            if (image.getWidth() > width) {
                width = (int) image.getWidth();
            }
        }

        width += 2 * Margin;
        height = y + Margin - interval;
        Blend blend = new Blend(BlendMode.SRC_OVER);
        blend.setBottomInput(new ColorInput(0, 0, width, height, bgColor));
        group.setEffect(blend);

        SnapshotParameters parameters = new SnapshotParameters();
        parameters.setFill(Color.TRANSPARENT);
        WritableImage newImage = group.snapshot(parameters, null);

        return newImage;
    } catch (Exception e) {
        logger.error(e.toString());
        return null;
    }
}
 
Example 19
Source File: ImageUtil.java    From Augendiagnose with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Retrieve an overlay image, warped due to pupil size and position.
 *
 * @param overlayType
 *            The overlay type.
 * @param side
 *            The side of the eye.
 * @param color
 *            The overlay color.
 * @param pupilXOffset
 *            The horizontal offset of the pupil.
 * @param pupilYOffset
 *            The vertical offset of the pupil.
 * @param pupilSize
 *            The relative size of the pupil.
 * @return The overlay image.
 */
private static Image getOverlayImage(final int overlayType, final RightLeft side, final Color color,
		final float pupilXOffset, final float pupilYOffset, final float pupilSize) {
	if (mCachedOverlayType != null && overlayType == mCachedOverlayType // BOOLEAN_EXPRESSION_COMPLEXITY
			&& side == mCachedOverlaySide && color.equals(mCachedOverlayColor)
			&& pupilXOffset == mCachedPupilXOffset && pupilYOffset == mCachedPupilYOffset && pupilSize == mCachedPupilSize) {
		return mCachedOverlay;
	}

	Image originalImage = getOverlayImage(overlayType, side, color);
	Canvas canvas = new Canvas(OVERLAY_SIZE, OVERLAY_SIZE);

	int overlayHalfSize = OVERLAY_SIZE / 2;
	int irisRadius = (int) (OVERLAY_CIRCLE_RATIO * overlayHalfSize);
	long irisRadiusSquare = irisRadius * irisRadius;
	float pupilXCenter = OVERLAY_SIZE * OVERLAY_CIRCLE_RATIO * pupilXOffset / (1 - pupilSize);
	float pupilYCenter = OVERLAY_SIZE * OVERLAY_CIRCLE_RATIO * pupilYOffset / (1 - pupilSize);
	float origPupilSize = ORIG_PUPIL_SIZES[overlayType];
	float linTransM = pupilSize == 1 ? 0 : (1 - origPupilSize) / (1 - pupilSize);
	float linTransB = 1 - linTransM;

	FloatMap floatMap = new FloatMap(OVERLAY_SIZE, OVERLAY_SIZE);
	for (int x = 0; x < OVERLAY_SIZE; x++) {
		int xPos = x - overlayHalfSize;
		float xPosP = xPos - pupilXCenter;

		for (int y = 0; y < OVERLAY_SIZE; y++) {
			int yPos = y - overlayHalfSize;
			float yPosP = yPos - pupilYCenter;

			long centerDistSquare = xPos * xPos + yPos * yPos;
			float pupilCenterDistSquare = xPosP * xPosP + yPosP * yPosP;

			if (centerDistSquare >= irisRadiusSquare) {
				floatMap.setSamples(x, y, 0, 0);
			}
			else if (pupilCenterDistSquare == 0) {
				floatMap.setSamples(x, y, -xPos / OVERLAY_SIZE, -yPos / OVERLAY_SIZE);
			}
			else {
				// Determine corresponding iris boundary point via quadratic equation
				float plusMinusTerm = (float) Math.sqrt(2 * xPosP * yPosP * pupilXCenter * pupilYCenter
						+ irisRadius * irisRadius * pupilCenterDistSquare
						- (pupilXCenter * pupilXCenter * yPosP * yPosP)
						- (pupilYCenter * pupilYCenter * xPosP * xPosP));

				float xBound = (yPosP * yPosP * pupilXCenter - yPosP * xPosP * pupilYCenter + xPosP * plusMinusTerm) / pupilCenterDistSquare;
				float yBound = (xPosP * xPosP * pupilYCenter - xPosP * yPosP * pupilXCenter + yPosP * plusMinusTerm) / pupilCenterDistSquare;

				// distance of the current point from the center - 1 corresponds to iris boundary
				float relativeDistance = (float) Math.sqrt(pupilCenterDistSquare
						/ ((xBound - pupilXCenter) * (xBound - pupilXCenter) + (yBound - pupilYCenter) * (yBound - pupilYCenter)));

				float sourceRelativeDistance = linTransM * relativeDistance + linTransB;
				if (relativeDistance < pupilSize) {
					sourceRelativeDistance -= linTransB * Math.pow(1 - relativeDistance / pupilSize, 1.1f); // MAGIC_NUMBER
				}

				float sourceX = xBound * sourceRelativeDistance;
				float sourceY = yBound * sourceRelativeDistance;

				floatMap.setSamples(x, y, (sourceX - xPos) / OVERLAY_SIZE, (sourceY - yPos) / OVERLAY_SIZE);
			}

		}
	}
	DisplacementMap displacementMap = new DisplacementMap(floatMap);
	canvas.getGraphicsContext2D().setEffect(displacementMap);
	canvas.getGraphicsContext2D().drawImage(originalImage, 0, 0, OVERLAY_SIZE, OVERLAY_SIZE);

	SnapshotParameters parameters = new SnapshotParameters();
	parameters.setFill(Color.TRANSPARENT);

	mCachedOverlay = canvas.snapshot(parameters, null);
	mCachedOverlayType = overlayType;
	mCachedOverlaySide = side;
	mCachedOverlayColor = color;
	mCachedPupilSize = pupilSize;
	mCachedPupilXOffset = pupilXOffset;
	mCachedPupilYOffset = pupilYOffset;
	return mCachedOverlay;
}
 
Example 20
Source File: ImageManufactureRichTextController.java    From MyBox with Apache License 2.0 4 votes vote down vote up
protected void makeImage() {
        try {
            if (webView == null || webEngine == null || !webView.isVisible()) {
                return;
            }

            synchronized (this) {
                if (task != null) {
                    return;
                }
                final double rotate = webView.getRotate();
                webView.setRotate(0);
//                webEngine.executeScript("document.body.style.backgroundColor = '"
//                        + FxmlColor.rgb2css((Color) bgRect.getFill()) + "'; opacity:" + opacity);
//                webView.setOpacity(1);
//                webEngine.executeScript("document.body.style.backgroundColor = 'rgba(0,0,0,0)';");

                // http://news.kynosarges.org/2017/02/01/javafx-snapshot-scaling/
                double scale = FxmlControl.dpiScale();
                final WritableImage snap = new WritableImage(
                        (int) Math.round(webView.getWidth() * scale),
                        (int) Math.round(webView.getHeight() * scale));
                final SnapshotParameters parameters = new SnapshotParameters();
                parameters.setTransform(Transform.scale(scale, scale));
                parameters.setFill(Color.TRANSPARENT);
                webView.snapshot(parameters, snap);
                if (!parent.editable.get()) {
                    return;
                }
                task = new SingletonTask<Void>() {
                    private Image transparent, blended;

                    @Override
                    protected boolean handle() {
                        try {
                            transparent = FxmlImageManufacture.replaceColor(snap,
                                    Color.WHITE, Color.TRANSPARENT, 0);

                            blended = FxmlImageManufacture.drawHTML(imageController.imageView.getImage(),
                                    transparent, imageController.maskRectangleData,
                                    (Color) bgRect.getFill(), opacity, arc,
                                    (int) rotate, marginsWidth);

                            if (task == null || isCancelled()) {
                                return false;
                            }

                            return blended != null;
                        } catch (Exception e) {
                            logger.error(e.toString());
                            return false;
                        }
                    }

                    @Override
                    protected void whenSucceeded() {
                        if (isPreview) {
                            webView.setRotate(rotate);
//                            ImageViewerController controller1
//                                    = (ImageViewerController) openStage(CommonValues.ImageFxml);
//                            controller1.loadImage(transparent);
                            ImageViewerController controller
                                    = (ImageViewerController) openStage(CommonValues.ImageViewerFxml);
                            controller.loadImage(blended);
                            controller.setAsPopped();
                        } else {
                            parent.updateImage(ImageOperation.RichText, null, null, blended, cost);
                            webView = null;
                        }
                    }

                };
                parent.openHandlingStage(task, Modality.WINDOW_MODAL);
                Thread thread = new Thread(task);
                thread.setDaemon(true);
                thread.start();
            }

        } catch (Exception e) {
            logger.error(e.toString());
        }
    }