Java Code Examples for javafx.embed.swing.SwingFXUtils

The following examples show how to use javafx.embed.swing.SwingFXUtils. These examples are extracted from open source projects. 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 Project: TelegramClone   Source File: HomeController.java    License: MIT License 6 votes vote down vote up
@FXML
void attachFile(MouseEvent event) {
    try {
        FileChooser fileChooser = new FileChooser();
        File imageFile = fileChooser.showOpenDialog(new Stage());
        BufferedImage bufferedImage = ImageIO.read(imageFile);
        Image image = SwingFXUtils.toFXImage(bufferedImage, null);
        currentlySelectedUser.messagesList.add(new MessageViewModel("", getCurrentTime(), false, true, image));
        messagesListView.scrollTo(currentlySelectedUser.messagesList.size());

    } catch (IOException e) {
        e.printStackTrace();
    }


}
 
Example 2
Source Project: SlidesRemote   Source File: QRCodeEngine.java    License: Apache License 2.0 6 votes vote down vote up
public static Image encode(String data, int width, int height) {
    try {
        BitMatrix byteMatrix = new QRCodeWriter().encode(data, BarcodeFormat.QR_CODE, width, height);
        BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        bufferedImage.createGraphics();
        Graphics2D graphics = (Graphics2D) bufferedImage.getGraphics();
        graphics.setColor(Color.decode("#00adb5"));
        graphics.fillRect(0, 0, width, height);
        graphics.setColor(Color.BLACK);
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                if (byteMatrix.get(i, j)) {
                    graphics.fillRect(i, j, 1, 1);
                }
            }
        }

        return SwingFXUtils.toFXImage(bufferedImage, null);
    } catch (WriterException ex) {
        ex.printStackTrace();
        return null;
    }
}
 
Example 3
Source Project: oim-fx   Source File: ChatFunction.java    License: MIT License 6 votes vote down vote up
public void saveWriteImage(ChatPane cp, Image image) {
	String fileName = dateFormat.format(new Date()).toString() + ".png";
	PathManager pm = appContext.getManager(PathManager.class);
	String savePath = pm.getScreenshotSavePath();
	String fullPath = savePath + fileName;
	try {
		OnlyFileUtil.checkOrCreateFolder(fullPath);
		File file = new File(fullPath);
		ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file);
		String path = WebImagePathUtil.pathToFileImageSource(fullPath);
		ChatWritePane cwp = cp.getChatWritePane();
		String tag = HtmlContentUtil.getImageTag("", "image", path, path, "");
		cwp.insertSelectionHtml(tag);
	} catch (IOException ex) {
	}
}
 
Example 4
Source Project: Path-of-Leveling   Source File: Gem.java    License: MIT License 6 votes vote down vote up
public void resizeImage(){
    BufferedImage before = SwingFXUtils.fromFXImage(gemIcon, null);
    int w = before.getWidth();
    int h = before.getHeight();
    // Create a new image of the proper size
    int w2 = (int) (w * 0.7);
    int h2 = (int) (h * 0.7);
    BufferedImage after = new BufferedImage(w2, h2, BufferedImage.TYPE_INT_ARGB);
    AffineTransform scaleInstance = AffineTransform.getScaleInstance(0.7, 0.7);
    AffineTransformOp scaleOp
        = new AffineTransformOp(scaleInstance, AffineTransformOp.TYPE_BILINEAR);

    after = scaleOp.filter(before, after);
    smallGemIcon = SwingFXUtils.toFXImage(after, null);
    //ImageIcon imageIcon = new ImageIcon(dimg);
}
 
Example 5
Source Project: Quelea   Source File: LivePanel.java    License: 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 6
private Image getQRImage() {
    if (qrImage == null) {
        QRCodeWriter qrCodeWriter = new QRCodeWriter();
        int qrWidth = 500;
        int qrHeight = 500;
        BitMatrix byteMatrix = null;
        try {
            byteMatrix = qrCodeWriter.encode(getMLURL(), BarcodeFormat.QR_CODE, qrWidth, qrHeight);
        } catch (WriterException ex) {
            LOGGER.log(Level.WARNING, "Error writing QR code", ex);
        }
        qrImage = MatrixToImageWriter.toBufferedImage(byteMatrix);
    }
    WritableImage fxImg = new WritableImage(500, 500);
    SwingFXUtils.toFXImage(qrImage, fxImg);
    return fxImg;
}
 
Example 7
Source Project: gitPic   Source File: MainController.java    License: MIT License 6 votes vote down vote up
/**
 * 从剪贴板复制
 */
@FXML
protected void copyByClipboard() {
    Clipboard clipboard = Clipboard.getSystemClipboard();
    if (clipboard.hasImage()) {
        Image image = clipboard.getImage();
        BufferedImage bImage = SwingFXUtils.fromFXImage(image, null);
        try {
            Path tempDirectory = Files.createTempDirectory(Constants.GITPIC_PREFIX);
            String tempFile = tempDirectory.toString() + File.separator + Constants.GITPIC_PREFIX + System.currentTimeMillis() + ".png";
            File file = new File(tempFile);
            ImageIO.write(bImage, "png", file);
            uploadImgFilePath = file.getAbsolutePath();
            copyAndGenerate();
            file.delete();// 删除临时图片
            Files.delete(tempDirectory);//删除临时目录
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
            showErrorMessage("从剪切板拷贝图片异常", e);
        }
    } else {
        showErrorMessage("剪切板中没有图片");
    }
}
 
Example 8
Source Project: MyBox   Source File: ImageManufactureController.java    License: Apache License 2.0 6 votes vote down vote up
protected void loadThumbnail(ImageHistory his) {
    try {
        if (his == null) {
            return;
        }
        String fname = his.getHistoryLocation();
        int width = AppVariables.getUserConfigInt("ThumbnailWidth", 100);
        String thumbname = FileTools.appendName(fname, "_thumbnail");
        File thumbfile = new File(thumbname);
        BufferedImage bufferedImage;
        if (thumbfile.exists()) {
            bufferedImage = ImageFileReaders.readImage(thumbfile);
        } else {
            bufferedImage = ImageFileReaders.readFileByWidth("png", fname, width);
        }
        if (bufferedImage != null) {
            his.setThumbnail(SwingFXUtils.toFXImage(bufferedImage, null));
        }
    } catch (Exception e) {
        logger.debug(e.toString());
    }
}
 
Example 9
Source Project: Java-11-Cookbook-Second-Edition   Source File: RobotAPIDemo.java    License: MIT License 6 votes vote down vote up
public static void captureScreen(){
	Platform.runLater(() -> {
		try{
					
			WritableImage screenCapture = new WritableImage(Double.valueOf(appStage.getWidth()).intValue(), 
			Double.valueOf(appStage.getHeight()).intValue());
			//WritableImage screenCapture = robot.getScreenCapture()
			robot.getScreenCapture(screenCapture, appStage.getX(), appStage.getY(), appStage.getWidth(), appStage.getHeight());

			BufferedImage screenCaptureBI = SwingFXUtils.fromFXImage(screenCapture, null);
			String timePart = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-dd-M-m-H-ss"));
			ImageIO.write(screenCaptureBI, "png", new File("screenCapture-" + timePart +".png"));
			Platform.exit();
		}catch(Exception ex){
			ex.printStackTrace();
		}
	});
}
 
Example 10
Source Project: MyBox   Source File: FxmlImageManufacture.java    License: Apache License 2.0 6 votes vote down vote up
public static Image blendImages(Image foreImage, Image backImage,
        ImagesRelativeLocation location, int x, int y,
        boolean intersectOnly, ImagesBlendMode blendMode, float opacity) {
    if (foreImage == null || backImage == null || blendMode == null) {
        return null;
    }
    BufferedImage source1 = SwingFXUtils.fromFXImage(foreImage, null);
    BufferedImage source2 = SwingFXUtils.fromFXImage(backImage, null);
    BufferedImage target = ImageBlend.blendImages(source1, source2,
            location, x, y, intersectOnly, blendMode, opacity);
    if (target == null) {
        target = source1;
    }
    Image newImage = SwingFXUtils.toFXImage(target, null);
    return newImage;
}
 
Example 11
Source Project: OpenLabeler   Source File: OpenCVUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Source OpenCV MAT is assumed to be in CvType.CV_8UC4
 * Return JavaFX Image in BGR format
 */
public static Image matToImage(Mat matImg) {
   int width = matImg.width(), height = matImg.height();

   Mat converted = new Mat();
   Imgproc.cvtColor(matImg, converted, Imgproc.COLOR_RGBA2BGR);
   byte[] pixels = new byte[width * height * 3];
   converted.get(0, 0, pixels);

   BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
   image.getRaster().setDataElements(0, 0, width, height, pixels);
   return SwingFXUtils.toFXImage(image, null);
}
 
Example 12
Source Project: MyBox   Source File: ImageBinary.java    License: Apache License 2.0 5 votes vote down vote up
public static int calculateThreshold(Image image) {
    try {
        BufferedImage bm = SwingFXUtils.fromFXImage(image, null);
        return calculateThreshold(bm);
    } catch (Exception e) {
        logger.error(e.toString());
        return -1;
    }
}
 
Example 13
Source Project: MyBox   Source File: FxmlImageManufacture.java    License: Apache License 2.0 5 votes vote down vote up
public static Image indicateRectangle(Image image,
        Color color, int lineWidth, DoubleRectangle rect) {
    BufferedImage source = SwingFXUtils.fromFXImage(image, null);
    BufferedImage target = mara.mybox.image.ImageScope.indicateRectangle(source,
            FxmlImageManufacture.toAwtColor(color), lineWidth, rect);
    Image newImage = SwingFXUtils.toFXImage(target, null);
    return newImage;
}
 
Example 14
Source Project: oim-fx   Source File: ChatListViewImpl.java    License: MIT License 5 votes vote down vote up
public void saveImage(ChatPanel cp, Image image) {
	String fileName = dateFormat.format(new Date()).toString() + ".png";
	PathManager pm = appContext.getManager(PathManager.class);
	String savePath = pm.getScreenshotSavePath();
	String path = savePath + fileName;
	try {
		OnlyFileUtil.checkOrCreateFolder(path);
		File file = new File(path);
		ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file);
		cp.insertImage("", "image", path, path);
	} catch (IOException ex) {
	}
}
 
Example 15
Source Project: oim-fx   Source File: ImageBox.java    License: MIT License 5 votes vote down vote up
public static Image getImagePath(String imagePath, int w, int h, int cornersWidth, int cornerHeight) {
	String key = imagePath + "_" + w + "_" + h + "_" + cornersWidth + "_" + cornerHeight;
	Image image = imageMap.get(key);
	if (null == image) {
		WritableImage writableImage = new WritableImage(w, h);
		BufferedImage bufferedImage = ImageUtil.getBufferedImage(imagePath, w, h, cornersWidth, cornerHeight);
		SwingFXUtils.toFXImage(bufferedImage, writableImage);
		image = writableImage;
	}
	return image;
	// BufferedImage bufferedImage =
	// ImageUtil.getRoundedCornerBufferedImage("Resources/Images/Head/User/90_100.gif",
	// 80, 80, 8, 8);
	// SwingFXUtils.toFXImage(bufferedImage, image);
}
 
Example 16
Source Project: MyBox   Source File: FxmlImageManufacture.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean same(Image imageA, Image imageB) {
    if (imageA == null || imageB == null
            || imageA.getWidth() != imageB.getWidth()
            || imageA.getHeight() != imageB.getHeight()) {
        return false;
    }
    return ImageManufacture.same(
            SwingFXUtils.fromFXImage(imageA, null),
            SwingFXUtils.fromFXImage(imageB, null));
}
 
Example 17
Source Project: MyBox   Source File: FxmlImageManufacture.java    License: Apache License 2.0 5 votes vote down vote up
public static Image blendImages(Image foreImage, Image backImage,
        int x, int y, ImagesBlendMode blendMode, float opacity) {
    if (foreImage == null || backImage == null || blendMode == null) {
        return null;
    }
    BufferedImage source1 = SwingFXUtils.fromFXImage(foreImage, null);
    BufferedImage source2 = SwingFXUtils.fromFXImage(backImage, null);
    BufferedImage target = ImageBlend.blendImages(source1, source2,
            x, y, blendMode, opacity);
    if (target == null) {
        target = source1;
    }
    Image newImage = SwingFXUtils.toFXImage(target, null);
    return newImage;
}
 
Example 18
Source Project: WebcamFX   Source File: CaptureCameraController.java    License: MIT License 5 votes vote down vote up
@FXML
private void btnSave() {
    isCapture = true; // Stop taking pictures

    File file = fileChooser.showSaveDialog(imageView.getScene().getWindow());
    if (file != null)
        try { // Save picture with .png extension
            ImageIO.write(SwingFXUtils.fromFXImage(imageView.getImage(), null), "PNG", file);
        } catch (IOException ex) {
            ex.printStackTrace(); // Can't save picture
        }
}
 
Example 19
Source Project: Path-of-Leveling   Source File: Util.java    License: MIT License 5 votes vote down vote up
public static Image charToImage(String className, String asc) {
    Image result = null;
    try {
        BufferedImage img = ImageIO.read(Util.class.getResource("/classes/" + className + "/" + asc + ".png"));
        result = SwingFXUtils.toFXImage(img, null);
    } catch (Exception ex) {
        m_logger.severe("Failed to load ascendancy image for class: " + className + " asc: " + asc);
    }

    return result;
}
 
Example 20
Source Project: Quelea   Source File: PresentationSlide.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new presentation slide.
 *
 * @param slide the underlying apache POI slide.
 */
public PresentationSlide(Slide slide, int numSlide) {
    SlideShow slideshow = slide.getSlideShow();
    if (Math.abs(slideshow.getPageSize().getHeight() - HEIGHT) > 0.1) {
        int adjustHeight = HEIGHT;
        int adjustWidth = (int) ((adjustHeight / slideshow.getPageSize().getHeight()) * slideshow.getPageSize().getWidth());
        scaleWidth = (double) adjustWidth / slideshow.getPageSize().getWidth();
        scaleHeight = (double) adjustHeight / slideshow.getPageSize().getHeight();
        slideshow.setPageSize(new Dimension(adjustWidth, adjustHeight));
    }
    BufferedImage originalImage = new BufferedImage((int) slideshow.getPageSize().getWidth(), (int) slideshow.getPageSize().getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = originalImage.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    try {
        g2.setTransform(AffineTransform.getScaleInstance(scaleWidth, scaleHeight));
        slide.draw(g2);
    } catch (Exception ex) {
        if (QueleaProperties.get().getUsePP()) {
            LOGGER.log(Level.INFO, "Couldn't use library to generate thumbnail, using default");
            draw(g2, originalImage.getWidth(), originalImage.getHeight(), numSlide);
        } else {
            throw ex;
        }
    }
    image = new WritableImage(originalImage.getWidth(), originalImage.getHeight());
    SwingFXUtils.toFXImage(originalImage, image);
    originalImage.flush();
    originalImage = null;
}
 
Example 21
Source Project: MyBox   Source File: FxmlImageManufacture.java    License: Apache License 2.0 5 votes vote down vote up
public static Image drawHTML(Image backImage, BufferedImage html,
            int htmlX, int htmlY, int htmlWdith, int htmlHeight) {
        if (html == null || backImage == null) {
            return backImage;
        }
        BufferedImage backBfImage = SwingFXUtils.fromFXImage(backImage, null);
//        BufferedImage htmlBfImage = SwingFXUtils.fromFXImage(html, null);
        BufferedImage target = ImageManufacture.drawHTML(backBfImage, html,
                htmlX, htmlY, htmlWdith, htmlHeight);
        Image newImage = SwingFXUtils.toFXImage(target, null);
        return newImage;
    }
 
Example 22
Source Project: Quelea   Source File: WebDrawer.java    License: GNU General Public License v3.0 5 votes vote down vote up
public Image getPreview(int x, int y) {
    WritableImage previewImage = new WritableImage(x, y);
    QueleaApp.get().getProjectionWindow().getCanvas().snapshot(new SnapshotParameters(), previewImage);
    BufferedImage bi = SwingFXUtils.fromFXImage((WritableImage) previewImage, null);
    SwingFXUtils.toFXImage(bi, previewImage);
    return previewImage;
}
 
Example 23
Source Project: Quelea   Source File: ThemePreviewPanel.java    License: GNU General Public License v3.0 5 votes vote down vote up
public Image getThemePreviewImage() {
    previewImage = new WritableImage(200, 150);
    canvas.snapshot(new SnapshotParameters(), previewImage);
    BufferedImage bi = SwingFXUtils.fromFXImage((WritableImage) previewImage, null);
    SwingFXUtils.toFXImage(bi, previewImage);

    return previewImage;
}
 
Example 24
Source Project: MyBox   Source File: ImageBinary.java    License: Apache License 2.0 5 votes vote down vote up
public static Image binary(Image image) {
    try {
        BufferedImage bm = SwingFXUtils.fromFXImage(image, null);
        bm = byteBinary(bm);
        return SwingFXUtils.toFXImage(bm, null);
    } catch (Exception e) {
        logger.error(e.toString());
        return image;
    }
}
 
Example 25
Source Project: houdoku   Source File: Data.java    License: MIT License 5 votes vote down vote up
/**
 * Save a JavaFX Image to the filesystem.
 *
 * @param image the Image to save
 * @param path  the Path to save the image
 * @throws IOException an IOException occurred when writing to the file
 */
private static void saveImage(Image image, Path path) throws IOException {
    // ensure path to file exists
    Files.createDirectories(path.getParent());

    BufferedImage bufferedImage = SwingFXUtils.fromFXImage(image, null);
    // convert to BufferedImage.TYPE_INT_RGB
    BufferedImage convertedImg = new BufferedImage(bufferedImage.getWidth(),
            bufferedImage.getHeight(), BufferedImage.TYPE_INT_RGB);
    convertedImg.getGraphics().drawImage(bufferedImage, 0, 0, null);
    ImageIO.write(convertedImg, "jpg", path.toFile());
}
 
Example 26
Source Project: MyBox   Source File: ImageBinary.java    License: Apache License 2.0 5 votes vote down vote up
public ImageBinary(Image image, ImageScope scope) {
    this.image = SwingFXUtils.fromFXImage(image, null);
    this.scope = scope;
    this.operationType = OperationType.BlackOrWhite;
    intPara1 = -1;
    grayed = false;
}
 
Example 27
Source Project: MyBox   Source File: ImageClipboard.java    License: Apache License 2.0 5 votes vote down vote up
public static String add(BufferedImage image, boolean putSystemClipboard) {
    try {
        String filename = AppVariables.getImageClipboardPath() + File.separator
                + (new Date().getTime()) + "_" + new Random().nextInt(1000);
        while (new File(filename + ".png").exists()) {
            filename = AppVariables.getImageClipboardPath() + File.separator
                    + (new Date().getTime()) + "_" + new Random().nextInt(1000);
        }
        if (!ImageFileWriters.writeImageFile(image, "png", filename + ".png")) {
            return null;
        }
        BufferedImage thumbnail = ImageManufacture.scaleImageWidthKeep(image,
                AppVariables.getUserConfigInt("ThumbnailWidth", 100));
        if (thumbnail == null) {
            return null;
        }
        if (!ImageFileWriters.writeImageFile(thumbnail, "png", filename + "_thumbnail.png")) {
            return null;
        }
        TableStringValues.add(TableKey, filename + ".png");
        TableStringValues.max(TableKey, max());

        if (putSystemClipboard) {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    ClipboardContent cc = new ClipboardContent();
                    cc.putImage(SwingFXUtils.toFXImage(image, null));
                    Clipboard.getSystemClipboard().setContent(cc);
                }
            });
        }

        return filename + ".png";
    } catch (Exception e) {
        logger.debug(e.toString());
        return null;
    }

}
 
Example 28
Source Project: MyBox   Source File: GameElimniationController.java    License: Apache License 2.0 5 votes vote down vote up
public void viewImage() {
    if (isSettingValues) {
        return;
    }
    imageView.setImage(null);
    imageLabel.setText("");
    ImageItem selected = imagesListview.getSelectionModel().getSelectedItem();
    if (selected == null) {
        return;
    }
    String address = selected.getAddress();
    if (selected.isInternel()) {
        imageView.setImage(new Image(address));
        imageView.setPreserveRatio(true);
        imageView.setFitHeight(Math.min(scrollPane.getHeight(), imageView.getImage().getHeight()));
        imageLabel.setText(message(selected.getComments()));
    } else if (selected.isColor()) {

    } else {
        try {
            File file = new File(address);
            if (file.exists()) {
                BufferedImage image = ImageIO.read(file);
                imageView.setImage(SwingFXUtils.toFXImage(image, null));
            } else {
            }
        } catch (Exception e) {
        }
    }
}
 
Example 29
Source Project: MyBox   Source File: ImageOCRController.java    License: Apache License 2.0 5 votes vote down vote up
@FXML
protected void scale() {
    if (isSettingValues || imageView.getImage() == null || scale <= 0) {
        return;
    }
    synchronized (this) {
        if (task != null) {
            return;
        }
        task = new SingletonTask<Void>() {
            private Image ocrImage;

            @Override
            protected boolean handle() {
                try {
                    BufferedImage bufferedImage = SwingFXUtils.fromFXImage(imageView.getImage(), null);
                    bufferedImage = ImageManufacture.scaleImage(bufferedImage, scale);
                    ocrImage = SwingFXUtils.toFXImage(bufferedImage, null);
                    return ocrImage != null;
                } catch (Exception e) {
                    error = e.toString();
                    return false;
                }
            }

            @Override
            protected void whenSucceeded() {
                setPreprocessImage(ocrImage);

            }

        };
        openHandlingStage(task, Modality.WINDOW_MODAL);
        Thread thread = new Thread(task);
        thread.setDaemon(true);
        thread.start();
    }
}
 
Example 30
Source Project: MyBox   Source File: ImageOCRController.java    License: Apache License 2.0 5 votes vote down vote up
@FXML
protected void binary() {
    if (isSettingValues || imageView.getImage() == null || threshold <= 0) {
        return;
    }
    synchronized (this) {
        if (task != null) {
            return;
        }
        task = new SingletonTask<Void>() {
            private Image ocrImage;

            @Override
            protected boolean handle() {
                try {
                    BufferedImage bufferedImage = SwingFXUtils.fromFXImage(imageView.getImage(), null);
                    ImageBinary bin = new ImageBinary(bufferedImage, threshold);
                    bufferedImage = bin.operateImage();
                    ocrImage = SwingFXUtils.toFXImage(bufferedImage, null);
                    return ocrImage != null;
                } catch (Exception e) {
                    error = e.toString();
                    return false;
                }
            }

            @Override
            protected void whenSucceeded() {
                setPreprocessImage(ocrImage);

            }

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