javafx.embed.swing.SwingFXUtils Java Examples
The following examples show how to use
javafx.embed.swing.SwingFXUtils.
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: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 6 votes |
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 #2
Source File: RobotAPIDemo.java From Java-11-Cookbook-Second-Edition with MIT License | 6 votes |
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 #3
Source File: ImageManufactureController.java From MyBox with Apache License 2.0 | 6 votes |
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 #4
Source File: MainController.java From gitPic with MIT License | 6 votes |
/** * 从剪贴板复制 */ @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 #5
Source File: MobileServerPreference.java From Quelea with GNU General Public License v3.0 | 6 votes |
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 #6
Source File: LivePanel.java From Quelea with GNU General Public License v3.0 | 6 votes |
/** * 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 #7
Source File: Gem.java From Path-of-Leveling with MIT License | 6 votes |
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 #8
Source File: ChatFunction.java From oim-fx with MIT License | 6 votes |
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 #9
Source File: HomeController.java From TelegramClone with MIT License | 6 votes |
@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 #10
Source File: QRCodeEngine.java From SlidesRemote with Apache License 2.0 | 6 votes |
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 #11
Source File: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 5 votes |
public static Image addText(Image image, String textString, java.awt.Font font, Color color, int x, int y, float transparent, int shadow, int angle, boolean isOutline, boolean isVertical) { BufferedImage source = SwingFXUtils.fromFXImage(image, null); BufferedImage target = mara.mybox.image.ImageManufacture.addText(source, textString, font, FxmlImageManufacture.toAwtColor(color), x, y, transparent, shadow, angle, isOutline, isVertical); Image newImage = SwingFXUtils.toFXImage(target, null); return newImage; }
Example #12
Source File: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 5 votes |
public static Image addShadowNoAlpha(Image image, int shadow, Color color) { if (image == null || shadow <= 0) { return image; } BufferedImage source = SwingFXUtils.fromFXImage(image, null); BufferedImage target = mara.mybox.image.ImageManufacture.addShadowNoAlpha(source, shadow, FxmlImageManufacture.toAwtColor(color)); Image newImage = SwingFXUtils.toFXImage(target, null); return newImage; }
Example #13
Source File: ImageClipboard.java From MyBox with Apache License 2.0 | 5 votes |
public static String add(Image image, boolean putSystemClipboard) { try { return add(SwingFXUtils.fromFXImage(image, null), putSystemClipboard); } catch (Exception e) { logger.debug(e.toString()); return null; } }
Example #14
Source File: OpenCVUtils.java From OpenLabeler with Apache License 2.0 | 5 votes |
/** * 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 #15
Source File: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 5 votes |
public static Image drawLines(Image image, DoubleLines penData, Color strokeColor, int strokeWidth, boolean dotted, float opacity) { if (penData == null || strokeColor == null) { return image; } BufferedImage source = SwingFXUtils.fromFXImage(image, null); BufferedImage target = mara.mybox.image.ImageManufacture.drawLines(source, penData, FxmlImageManufacture.toAwtColor(strokeColor), strokeWidth, dotted, opacity); Image newImage = SwingFXUtils.toFXImage(target, null); return newImage; }
Example #16
Source File: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 5 votes |
public static Image drawLines(Image image, DoublePolyline polyline, Color strokeColor, int strokeWidth, boolean dotted, float opacity) { if (polyline == null || strokeColor == null) { return image; } BufferedImage source = SwingFXUtils.fromFXImage(image, null); BufferedImage target = mara.mybox.image.ImageManufacture.drawLines(source, polyline, FxmlImageManufacture.toAwtColor(strokeColor), strokeWidth, dotted, opacity); Image newImage = SwingFXUtils.toFXImage(target, null); return newImage; }
Example #17
Source File: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 5 votes |
public static Image drawPolygon(Image image, DoublePolygon polygon, Color strokeColor, int strokeWidth, boolean dotted, boolean isFill, Color fillColor, float opacity) { if (polygon == null || strokeColor == null) { return image; } BufferedImage source = SwingFXUtils.fromFXImage(image, null); BufferedImage target = mara.mybox.image.ImageManufacture.drawPolygon(source, polygon, FxmlImageManufacture.toAwtColor(strokeColor), strokeWidth, dotted, isFill, FxmlImageManufacture.toAwtColor(fillColor), opacity); Image newImage = SwingFXUtils.toFXImage(target, null); return newImage; }
Example #18
Source File: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 5 votes |
public static Image drawEllipse(Image image, DoubleEllipse ellipse, Color strokeColor, int strokeWidth, boolean dotted, boolean isFill, Color fillColor, float opacity) { if (ellipse == null || strokeColor == null) { return image; } BufferedImage source = SwingFXUtils.fromFXImage(image, null); BufferedImage target = mara.mybox.image.ImageManufacture.drawEllipse(source, ellipse, FxmlImageManufacture.toAwtColor(strokeColor), strokeWidth, dotted, isFill, FxmlImageManufacture.toAwtColor(fillColor), opacity); Image newImage = SwingFXUtils.toFXImage(target, null); return newImage; }
Example #19
Source File: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 5 votes |
public static Image addPicture(Image image, Image picture, int x, int y, int w, int h, boolean keepRatio, float transparent) { if (image == null) { return null; } if (picture == null) { return image; } BufferedImage source = SwingFXUtils.fromFXImage(image, null); BufferedImage pic = SwingFXUtils.fromFXImage(picture, null); BufferedImage target = mara.mybox.image.ImageManufacture.addPicture(source, pic, x, y, w, h, keepRatio, transparent); Image newImage = SwingFXUtils.toFXImage(target, null); return newImage; }
Example #20
Source File: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 5 votes |
public static Image addShadowAlpha(Image image, int shadow, Color color) { if (image == null || shadow <= 0) { return image; } BufferedImage source = SwingFXUtils.fromFXImage(image, null); BufferedImage target = mara.mybox.image.ImageManufacture.addShadowAlpha(source, shadow, FxmlImageManufacture.toAwtColor(color)); Image newImage = SwingFXUtils.toFXImage(target, null); return newImage; }
Example #21
Source File: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 5 votes |
public static Image scaleImage(Image image, int width, int height, boolean keepRatio, int keepType) { BufferedImage source = SwingFXUtils.fromFXImage(image, null); BufferedImage target = mara.mybox.image.ImageManufacture.scaleImage(source, width, height, keepRatio, keepType); Image newImage = SwingFXUtils.toFXImage(target, null); return newImage; }
Example #22
Source File: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 5 votes |
public static Image scaleImage(Image image, int width, int height) { if (width == image.getWidth() && height == image.getHeight()) { return image; } BufferedImage source = SwingFXUtils.fromFXImage(image, null); BufferedImage target = mara.mybox.image.ImageManufacture.scaleImage(source, width, height); Image newImage = SwingFXUtils.toFXImage(target, null); return newImage; }
Example #23
Source File: TableImageFileCell.java From MyBox with Apache License 2.0 | 5 votes |
@Override public TableCell<T, String> call(TableColumn<T, String> param) { final ImageView imageview = new ImageView(); imageview.setPreserveRatio(true); imageview.setFitWidth(imageSize); imageview.setFitHeight(imageSize); TableCell<T, String> cell = new TableCell<T, String>() { @Override public void updateItem(String item, boolean empty) { super.updateItem(item, empty); if (empty || item == null) { setText(null); setGraphic(null); return; } try { File file = new File(item.toString()); BufferedImage image = ImageIO.read(file); imageview.setImage(SwingFXUtils.toFXImage(image, null)); setGraphic(imageview); } catch (Exception e) { setText(null); setGraphic(null); } } }; return cell; }
Example #24
Source File: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 5 votes |
public static Image drawHTML(Image backImage, Image html, DoubleRectangle bkRect, Color bkColor, float bkOpacity, int bkarc, int rotate, int margin) { if (html == null || backImage == null || bkRect == null) { return backImage; } BufferedImage backBfImage = SwingFXUtils.fromFXImage(backImage, null); BufferedImage htmlBfImage = SwingFXUtils.fromFXImage(html, null); BufferedImage target = ImageManufacture.drawHTML(backBfImage, htmlBfImage, bkRect, ImageColor.converColor(bkColor), bkOpacity, bkarc, rotate, margin); Image newImage = SwingFXUtils.toFXImage(target, null); return newImage; }
Example #25
Source File: ImageManufacturePaneController.java From MyBox with Apache License 2.0 | 5 votes |
public void loadOutlineSource(Image image) { if (image == null) { maskView.setImage(null); return; } loadOutlineSource(SwingFXUtils.fromFXImage(image, null)); }
Example #26
Source File: ImageGray.java From MyBox with Apache License 2.0 | 5 votes |
public static Image gray(Image image) { try { BufferedImage bm = SwingFXUtils.fromFXImage(image, null); bm = intGray(bm); return SwingFXUtils.toFXImage(bm, null); } catch (Exception e) { logger.error(e.toString()); return image; } }
Example #27
Source File: ImageOCRController.java From MyBox with Apache License 2.0 | 5 votes |
@FXML protected void rotate() { if (isSettingValues || imageView.getImage() == null || rotate == 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.rotateImage(bufferedImage, rotate); 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 #28
Source File: ImageOCRController.java From MyBox with Apache License 2.0 | 5 votes |
@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(); } }
Example #29
Source File: ImageOCRController.java From MyBox with Apache License 2.0 | 5 votes |
@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 File: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 5 votes |
public static Image addArc(Image image, int arc, Color bgColor) { if (image == null || arc <= 0) { return image; } BufferedImage source = SwingFXUtils.fromFXImage(image, null); BufferedImage target = mara.mybox.image.ImageManufacture.addArc(source, arc, FxmlImageManufacture.toAwtColor(bgColor)); Image newImage = SwingFXUtils.toFXImage(target, null); return newImage; }