Java Code Examples for javafx.embed.swing.SwingFXUtils#toFXImage()
The following examples show how to use
javafx.embed.swing.SwingFXUtils#toFXImage() .
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: 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 2
Source File: ImageItem.java From MyBox with Apache License 2.0 | 5 votes |
public final void readImage() { try { image = null; if (isInternel()) { image = new ImageView(new Image(address)).getImage(); } else if (isFile()) { File file = new File(address); if (file.exists()) { BufferedImage bf = ImageIO.read(file); image = SwingFXUtils.toFXImage(bf, null); } } } catch (Exception e) { } }
Example 3
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 4
Source File: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 5 votes |
public static Image drawRectangle(Image image, DoubleRectangle rect, Color strokeColor, int strokeWidth, int arcWidth, boolean dotted, boolean isFill, Color fillColor, float opacity) { if (rect == null || strokeColor == null) { return image; } BufferedImage source = SwingFXUtils.fromFXImage(image, null); BufferedImage target = mara.mybox.image.ImageManufacture.drawRectangle(source, rect, FxmlImageManufacture.toAwtColor(strokeColor), strokeWidth, arcWidth, dotted, isFill, FxmlImageManufacture.toAwtColor(fillColor), opacity); Image newImage = SwingFXUtils.toFXImage(target, null); return newImage; }
Example 5
Source File: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 5 votes |
public static Image indicateEllipse(Image image, Color color, int lineWidth, DoubleEllipse ellipse) { BufferedImage source = SwingFXUtils.fromFXImage(image, null); BufferedImage target = mara.mybox.image.ImageScope.indicateEllipse(source, FxmlImageManufacture.toAwtColor(color), lineWidth, ellipse); Image newImage = SwingFXUtils.toFXImage(target, null); return newImage; }
Example 6
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; }
Example 7
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 8
Source File: ImageBinary.java From MyBox with Apache License 2.0 | 5 votes |
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 9
Source File: WebBrowserBoxController.java From MyBox with Apache License 2.0 | 5 votes |
@FXML protected void load() { try { webEngine.getLoadWorker().cancel(); if (url == null) { return; } bottomLabel.setText(AppVariables.message("Loading...")); final String address = url.toString().toLowerCase(); his = new BrowserHistory(); his.setAddress(address); his.setVisitTime(new Date().getTime()); his.setTitle(address); webEngine.load(address); File iconFile = new File(MyboxDataPath + File.separator + "icons" + File.separator + url.getHost() + ".png"); if (iconFile.exists()) { his.setIcon(iconFile.getAbsolutePath()); if (tab != null) { BufferedImage image = ImageIO.read(iconFile); if (image != null) { ImageView tabImage = new ImageView(SwingFXUtils.toFXImage(image, null)); tabImage.setFitWidth(20); tabImage.setFitHeight(20); tab.setGraphic(tabImage); } } } TableBrowserHistory.write(his); } catch (Exception e) { logger.error(e.toString()); } }
Example 10
Source File: PresentationSlide.java From Quelea with GNU General Public License v3.0 | 5 votes |
/** * 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 11
Source File: ImageInformation.java From MyBox with Apache License 2.0 | 5 votes |
public static ImageInformation loadImage(File file, int loadWidth, int frameIndex, ImageFileInformation imageFileInformation, boolean needSampled) { if (imageFileInformation == null || imageFileInformation.getImageInformation() == null) { return null; } String fileName = file.getAbsolutePath(); String format = FileTools.getFileSuffix(fileName).toLowerCase(); ImageInformation imageInfo = imageFileInformation.getImageInformation(); BufferedImage bufferImage; if (needSampled) { bufferImage = ImageFileReaders.readFileByWidth(format, fileName, imageInfo.getSizes().get("sampledWidth").intValue()); } else { bufferImage = ImageFileReaders.readImage(file); } boolean needScale = false; if (!"ico".equals(format) && !"icon".equals(format)) { needScale = (loadWidth > 0 && loadWidth != bufferImage.getWidth()); if (needScale && !needSampled) { bufferImage = ImageManufacture.scaleImageWidthKeep(bufferImage, loadWidth); } } Image theImage = SwingFXUtils.toFXImage(bufferImage, null); imageInfo.setImage(theImage); imageInfo.setImageType(bufferImage.getType()); imageInfo.setIsSampled(needSampled); imageInfo.setIsScaled(needScale); imageInfo.setWidth(bufferImage.getWidth()); imageInfo.setHeight(bufferImage.getHeight()); // imageInfo.setIsMultipleFrames(imageFileInformation.getNumberOfImages() > 1); return imageInfo; }
Example 12
Source File: Util.java From Path-of-Leveling with MIT License | 5 votes |
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 13
Source File: PixelsOperation.java From MyBox with Apache License 2.0 | 5 votes |
public Image operateFxImage() { BufferedImage target = operate(); if (target == null) { return null; } return SwingFXUtils.toFXImage(target, null); }
Example 14
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 15
Source File: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 5 votes |
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 16
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 17
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 18
Source File: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 4 votes |
public static Image scaleImage(Image image, int width) { BufferedImage source = SwingFXUtils.fromFXImage(image, null); BufferedImage target = mara.mybox.image.ImageManufacture.scaleImageWidthKeep(source, width); Image newImage = SwingFXUtils.toFXImage(target, null); return newImage; }
Example 19
Source File: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 4 votes |
public static Image clearAlpha(Image image) { BufferedImage source = SwingFXUtils.fromFXImage(image, null); BufferedImage target = mara.mybox.image.ImageManufacture.removeAlpha(source); Image newImage = SwingFXUtils.toFXImage(target, null); return newImage; }
Example 20
Source File: ImageManufactureController.java From MyBox with Apache License 2.0 | 4 votes |
public void referenceSelected(final File file) { try { if (file == null) { return; } recordFileOpened(file); synchronized (this) { if (task != null) { return; } task = new SingletonTask<Void>() { private ImageFileInformation finfo; private Image refImage; @Override protected boolean handle() { finfo = ImageFileReaders.readImageFileMetaData(file); if (finfo == null || finfo.getImageInformation() == null) { return false; } BufferedImage bufferedImage = ImageFileReaders.readImage(file); if (task == null || isCancelled() || bufferedImage == null) { return false; } refImage = SwingFXUtils.toFXImage(bufferedImage, null); if (task == null || isCancelled() || refImage == null) { return false; } return true; } @Override protected void whenSucceeded() { refFile = file; refInformation = finfo.getImageInformation(); refImageController.init(refFile, refImage, message("ReferenceImage")); refImageController.xZoomStep = (int) (refImage.getWidth() * zoomStep / 100); refImageController.yZoomStep = (int) (refImage.getHeight() * zoomStep / 100); } }; openHandlingStage(task, Modality.WINDOW_MODAL); Thread thread = new Thread(task); thread.setDaemon(true); thread.start(); } } catch (Exception e) { // logger.error(e.toString()); } }