Java Code Examples for javafx.scene.image.ImageView#getFitHeight()

The following examples show how to use javafx.scene.image.ImageView#getFitHeight() . 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: FxmlControl.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public static void zoomOut(ScrollPane sPane, ImageView iView, int xZoomStep,
        int yZoomStep) {
    double currentWidth = iView.getFitWidth();
    if (currentWidth == -1) {
        currentWidth = iView.getImage().getWidth();
    }
    if (currentWidth <= xZoomStep) {
        return;
    }
    iView.setFitWidth(currentWidth - xZoomStep);
    double currentHeight = iView.getFitHeight();
    if (currentHeight == -1) {
        currentHeight = iView.getImage().getHeight();
    }
    if (currentHeight <= yZoomStep) {
        return;
    }
    iView.setFitHeight(currentHeight - yZoomStep);
    FxmlControl.moveXCenter(sPane, iView);
}
 
Example 2
Source File: SceneMainController.java    From tet-java-client with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void updateEye(Pane root, ImageView eyeImageView, GazeData.Eye eye, double angle, double scale)
{
    Point2D p = GazeUtils.getRelativeToRect(
            eye.pupilCenterCoordinates,
            (int) Math.round(root.getScene().getWidth()),
            (int) Math.round(root.getScene().getHeight())
    );

    p.x -= eyeImageView.getFitWidth() * .5d;
    p.y -= eyeImageView.getFitHeight() * .5d;

    eyeImageView.setX(p.x);
    eyeImageView.setY(p.y);
    eyeImageView.setRotate(angle);
    eyeImageView.setScaleX(scale);
    eyeImageView.setScaleY(scale);
}
 
Example 3
Source File: FxmlControl.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static void zoomIn(ScrollPane sPane, ImageView iView, int xZoomStep,
        int yZoomStep) {
    double currentWidth = iView.getFitWidth();
    if (currentWidth == -1) {
        currentWidth = iView.getImage().getWidth();
    }
    iView.setFitWidth(currentWidth + xZoomStep);
    double currentHeight = iView.getFitHeight();
    if (currentHeight == -1) {
        currentHeight = iView.getImage().getHeight();
    }
    iView.setFitHeight(currentHeight + yZoomStep);
    FxmlControl.moveXCenter(sPane, iView);
}
 
Example 4
Source File: ModelImportDialog.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
protected boolean validate(@NotNull final VarTable vars) {

    final ImageView imageView = getImageView();

    if (!vars.has(PROP_FILE)) {
        imageView.setImage(null);
        return false;
    }

    final Path file = vars.get(PROP_FILE);

    if (!JmeFilePreviewManager.isModelFile(file)) {
        imageView.setImage(null);
        return false;
    }

    final Path renderedFile = getRenderedFile();
    if (renderedFile != null && file.equals(renderedFile)) {
        return super.validate(vars);
    }

    final int width = (int) imageView.getFitWidth();
    final int height = (int) imageView.getFitHeight();

    final JmeFilePreviewManager previewManager = JmeFilePreviewManager.getInstance();
    previewManager.showExternal(file, width, height);

    final ImageView sourceView = previewManager.getImageView();
    final ObjectProperty<Image> imageProperty = imageView.imageProperty();
    imageProperty.bind(sourceView.imageProperty());

    setRenderedFile(file);

    return super.validate(vars);
}
 
Example 5
Source File: JmeObjectFilePreview.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
public void show(@NotNull final Path file) {
    super.show(file);

    final ImageView imageView = getGraphicsNode();
    final int width = (int) imageView.getFitWidth();
    final int height = (int) imageView.getFitHeight();

    final JmeFilePreviewManager previewManager = JmeFilePreviewManager.getInstance();
    previewManager.show(file, width, height);

    final ImageView sourceView = previewManager.getImageView();
    imageView.imageProperty().bind(sourceView.imageProperty());
}
 
Example 6
Source File: JmeObjectFilePreview.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
public void show(@NotNull final String resource) {
    super.show(resource);

    final ImageView imageView = getGraphicsNode();
    final int width = (int) imageView.getFitWidth();
    final int height = (int) imageView.getFitHeight();

    final JmeFilePreviewManager previewManager = JmeFilePreviewManager.getInstance();
    previewManager.show(resource, width, height);

    final ImageView sourceView = previewManager.getImageView();
    imageView.imageProperty().bind(sourceView.imageProperty());
}
 
Example 7
Source File: ImageFilePreview.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
public void show(@NotNull final Path file) {
    super.show(file);

    final ImageView imageView = getGraphicsNode();
    final int width = (int) imageView.getFitWidth();
    final int height = (int) imageView.getFitHeight();

    imageView.setImage(JAVA_FX_IMAGE_MANAGER.getImagePreview(file, width, height));
}
 
Example 8
Source File: ImageFilePreview.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
public void show(@NotNull final String resource) {
    super.show(resource);

    final ImageView imageView = getGraphicsNode();
    final int width = (int) imageView.getFitWidth();
    final int height = (int) imageView.getFitHeight();

    imageView.setImage(JAVA_FX_IMAGE_MANAGER.getImagePreview(resource, width, height));
}
 
Example 9
Source File: ImagesBrowserController.java    From MyBox with Apache License 2.0 4 votes vote down vote up
private void makeImagePopup(VBox imageBox, ImageInformation imageInfo,
        ImageView iView) {
    try {
        File file = imageInfo.getImageFileInformation().getFile();
        final Image iImage = imageInfo.getImage();
        imagePop = new Popup();
        imagePop.setWidth(popSize + 40);
        imagePop.setHeight(popSize + 40);
        imagePop.setAutoHide(true);

        VBox vbox = new VBox();
        VBox.setVgrow(vbox, Priority.ALWAYS);
        HBox.setHgrow(vbox, Priority.ALWAYS);
        vbox.setMaxWidth(Double.MAX_VALUE);
        vbox.setMaxHeight(Double.MAX_VALUE);
        vbox.setStyle("-fx-background-color: white;");
        imagePop.getContent().add(vbox);

        popView = new ImageView();
        popView.setImage(iImage);
        if (iImage.getWidth() > iImage.getHeight()) {
            popView.setFitWidth(popSize);
        } else {
            popView.setFitHeight(popSize);
        }
        popView.setPreserveRatio(true);
        vbox.getChildren().add(popView);

        popText = new Text();
        popText.setStyle("-fx-font-size: 1.0em;");

        vbox.getChildren().add(popText);
        vbox.setPadding(new Insets(15, 15, 15, 15));

        String info = imageInfo.getFileName() + "\n"
                + AppVariables.message("Format") + ":" + imageInfo.getImageFormat() + "  "
                + AppVariables.message("ModifyTime") + ":" + DateTools.datetimeToString(file.lastModified()) + "\n"
                + AppVariables.message("Size") + ":" + FileTools.showFileSize(file.length()) + "  "
                + AppVariables.message("Pixels") + ":" + imageInfo.getWidth() + "x" + imageInfo.getHeight() + "\n"
                + AppVariables.message("LoadedSize") + ":"
                + (int) iView.getImage().getWidth() + "x" + (int) iView.getImage().getHeight() + "  "
                + AppVariables.message("DisplayedSize") + ":"
                + (int) iView.getFitWidth() + "x" + (int) iView.getFitHeight();
        popText.setText(info);
        popText.setWrappingWidth(popSize);
        Bounds bounds = imageBox.localToScreen(imageBox.getBoundsInLocal());
        imagePop.show(imageBox, bounds.getMinX() + bounds.getWidth() / 2, bounds.getMinY());

    } catch (Exception e) {
        logger.debug(e.toString());
    }
}
 
Example 10
Source File: DfsImagePainter.java    From Image-Cipher with Apache License 2.0 4 votes vote down vote up
/**
 * Depth First Search algorithm used to color image. This specific implementation uses stack,
 * because it will prevent possible StackOverflowError which would occur if it gets too big image
 * to traverse.
 *
 * @param file Image file
 * @param iterations Number of iterations
 * @param penColor Color of ink that will be used to color image
 * @param animationPause Duration of break between iterations
 * @param preview ImageView that displays live changes done by algorithm
 * @return BufferedImage - it is returned at the end of painting
 * @throws IOException May occur while reading the image file
 */
public static void paintImage(@NotNull File file,
    int iterations,
    @NotNull Color penColor,
    int animationPause,
    @NotNull ImageView preview,
    @NotNull Point point) throws IOException {
  logger.debug("DFS painting image, " + point.toString());
  BufferedImage image = ImageIO.read(file);
  int imageY = image.getHeight();
  int imageX = image.getWidth();

  double scaleX = preview.getFitWidth() > 0 ? (double) imageX / preview.getFitWidth() : 1;
  double scaleY = preview.getFitHeight() > 0 ? (double) imageY / preview.getFitHeight() : 1;

  int startPointX = (int) (point.x * scaleX);
  int startPointY = (int) (point.y * scaleY);

  int startColor = image.getRGB(startPointX, startPointY);

  Stack<Pixel> stack = new Stack<>();
  stack.push(new Pixel(startPointX, startPointY, startColor));

  int counter = 0;
  while (!stack.isEmpty() && counter < iterations) {
    Pixel pixel = stack.pop();
    image.setRGB(pixel.x, pixel.y, ColorParser.getColor(penColor));

    if (preview != null) {
      preview.setImage(SwingFXUtils.toFXImage(image, null));
    }

    if (pixel.y < imageY - 1 && image.getRGB(pixel.x, pixel.y + 1) == startColor) {
      stack.push(new Pixel(pixel.x, pixel.y + 1, startColor));
      counter++;
    }

    if (pixel.y > 0 && image.getRGB(pixel.x, pixel.y - 1) == startColor) {
      stack.push(new Pixel(pixel.x, pixel.y - 1, startColor));
      counter++;
    }

    if (pixel.x < imageX - 1 && image.getRGB(pixel.x + 1, pixel.y) == startColor) {
      stack.push(new Pixel(pixel.x + 1, pixel.y, startColor));
      counter++;
    }

    if (pixel.x > 0 && image.getRGB(pixel.x - 1, pixel.y) == startColor) {
      stack.push(new Pixel(pixel.x - 1, pixel.y, startColor));
      counter++;
    }

    try {
      Thread.sleep(animationPause);
    } catch (InterruptedException e) {
      logger.debug("Interrupting DFS painting thread: " + e.getMessage());
      return;
    }
  }
}
 
Example 11
Source File: BfsImagePainter.java    From Image-Cipher with Apache License 2.0 4 votes vote down vote up
/**
 * Breadth First Search algorithm to color pixels in image.
 *
 * @param file Image file
 * @param iterations Number of iterations
 * @param penColor Color of ink that will be used to color image
 * @param animationPause Duration of break between iterations
 * @param preview ImageView that displays live changes done by algorithm
 * @return BufferedImage - it is returned at the end of painting
 * @throws IOException May occur while reading the image file
 */
public static void paintImage(@NotNull File file,
    int iterations,
    @NotNull Color penColor,
    int animationPause,
    @NotNull ImageView preview,
    @NotNull Point point) throws IOException {
  logger.debug("BFS painting image, " + point.toString());
  BufferedImage image = ImageIO.read(file);
  int imageY = image.getHeight();
  int imageX = image.getWidth();

  double scaleX = preview.getFitWidth() > 0 ? (double) imageX / preview.getFitWidth() : 1;
  double scaleY = preview.getFitHeight() > 0 ? (double) imageY / preview.getFitHeight() : 1;

  int startPointX = (int) (point.x * scaleX);
  int startPointY = (int) (point.y * scaleY);

  int startColor = image.getRGB(startPointX, startPointY);

  Queue<Pixel> queue = new LinkedList<>();
  queue.add(new Pixel(startPointX, startPointY, startColor));

  int counter = 0;
  while (!queue.isEmpty() && counter < iterations) {
    Pixel pixel = queue.poll();
    image.setRGB(pixel.x, pixel.y, ColorParser.getColor(penColor));

    preview.setImage(SwingFXUtils.toFXImage(image, null));

    if (pixel.y < imageY - 1
        && image.getRGB(pixel.x, pixel.y + 1) == startColor) {
      queue.add(new Pixel(pixel.x, pixel.y + 1, startColor));
      counter++;
    }

    if (pixel.y > 0
        && image.getRGB(pixel.x, pixel.y - 1) == startColor) {
      queue.add(new Pixel(pixel.x, pixel.y - 1, startColor));
      counter++;
    }

    if (pixel.x < imageX - 1
        && image.getRGB(pixel.x + 1, pixel.y) == startColor) {
      queue.add(new Pixel(pixel.x + 1, pixel.y, startColor));
    }

    if (pixel.x > 0
        && image.getRGB(pixel.x - 1, pixel.y) == startColor) {
      queue.add(new Pixel(pixel.x - 1, pixel.y, startColor));
      counter++;
    }

    try {
      Thread.sleep(animationPause);
    } catch (InterruptedException e) {
      logger.info("Interrupting BFS painting thread");
      return;
    }
  }
}