private void updatePlaceholder(Node newView) { if (view.getWidth() > 0 && view.getHeight() > 0) { SnapshotParameters parameters = new SnapshotParameters(); parameters.setFill(Color.TRANSPARENT); Image placeholderImage = view.snapshot(parameters, new WritableImage((int) view.getWidth(), (int) view.getHeight())); placeholder.setImage(placeholderImage); placeholder.setFitWidth(placeholderImage.getWidth()); placeholder.setFitHeight(placeholderImage.getHeight()); } else { placeholder.setImage(null); } placeholder.setVisible(true); placeholder.setOpacity(1.0); view.getChildren().setAll(placeholder, newView); placeholder.toFront(); } }
public double getHeight() { if (this.image != null) return image.getHeight(); else return 480; }
public static double getMatchingHeight(double width, Image i) { return ((i.getHeight() * width) / i.getWidth()); }
public static double getMatchingWidth(double height, Image i) { return ((i.getWidth() * height) / i.getHeight()); }
private synchronized void addToCache(ImageIdentifier identifier, Image image) { cleanCache((int) image.getHeight() * (int) image.getWidth()); cache.put(identifier, new WeakReference<Image>(image)); updateUsage(identifier); pixelCount = pixelCount + (int) image.getHeight() * (int) image.getWidth(); }
public static int[] getRGB(Image image) { return getRGB(image, 0, 0, (int) image.getWidth(), (int) image.getHeight()); }
public static Image progressiveResize(Image image, int width, int height, InterpolationType type) { if (width <= 0 || height <= 0) { throw new IllegalArgumentException("Dimension must be > 0 (" + width + "/" + height + ")"); } if (image.getWidth() == width && image.getHeight() == height) { return new WritableImage(image.getPixelReader(), width, height); } if (image.getWidth() * 2 < width && image.getHeight() * 2 < height) { Image resizedImage = fastResize(image, (int) image.getWidth() * 2, (int) image.getHeight() * 2); return progressiveResize(resizedImage, width, height); } if (image.getWidth() / 2 > width && image.getHeight() / 2 > height) { Image resizedImage = fastResize(image, (int) image.getWidth() / 2, (int) image.getHeight() / 2); return progressiveResize(resizedImage, width, height); } return resizeByAwt(image, width, height, type); }
/** * {@inheritDoc} */ @Override protected Collection<Decoration> createRequiredDecorations(Control target) { return Arrays.asList(new GraphicDecoration(new ImageView(REQUIRED_IMAGE),Pos.TOP_LEFT, REQUIRED_IMAGE.getWidth()/2, REQUIRED_IMAGE.getHeight()/2)); }
public static Image fitInDimensionAndCutEdges(Image image, double width, double heigth) { Dimension2D newImageDimension = UiUtilities.shouldFitIn(image.getWidth(), image.getHeight(), width, heigth); Image resizedImage = fastResize(image, newImageDimension); return clipImage(resizedImage, new Rectangle2D((resizedImage.getWidth() - width) / 2, (resizedImage.getHeight() - heigth) / 2, width, heigth)); } }
public static Image filter(Image image, ImageFilter filter) { int width = (int) image.getWidth(); int height = (int) image.getHeight(); WritableImage filteredImage = new WritableImage(width, height); int[] inPixels = getRGB(image); int[] outPixels = filter.filter(width, height, inPixels); setRGB(filteredImage, 0, 0, width, height, outPixels); return filteredImage; }
public OpenPatricianSmallWaxButtonSkin(final OpenPatricianSmallWaxButton button) { super(button); InputStream is = getClass().getResourceAsStream("sealingWaxFlattend.png"); Image img = new Image(is); final ImageView imageView = new ImageView(img); final Label label = new Label(); label.textProperty().bind(button.textProperty()); label.getStyleClass().add("OpenPatricianSmallWaxButtonLabeled"); label.onMouseClickedProperty().bind(button.onActionProperty()); label.textProperty().bind(button.textProperty()); imageView.onMouseReleasedProperty().bind(button.onActionProperty()); StackPane stack = new StackPane(); stack.getChildren().addAll(imageView, label); Group group = new Group(stack); group.setManaged(false); button.setPrefHeight(img.getHeight()); button.setPrefWidth(img.getWidth()); button.setMaxHeight(img.getHeight()); getChildren().add(group); }
public void setCenter(Point2D center) { this.center = center; this.sprite.translateXProperty().set(this.center.getX() - this.sprite.getImage().getWidth() / 2d); this.sprite.translateYProperty().set(this.center.getY() - this.sprite.getImage().getHeight() / 2d); } // END setCenter
private void setUpImageView() { String imageName = getImageNameFromScene(); Image tmpImg = xmlLoader.getImage(imageName); ImageData imgData = xmlLoader.getImageData(imageName); Dimension2D targetDim = new Dimension2D(controlWidth, controlHeight); ImageScaleState state = new ImageScaleState(new Dimension2D(tmpImg.getWidth(), tmpImg.getHeight()), targetDim, imgData.getCrop(), imgData.getMaxCrop()); logger.debug("State of the port scene before: " + state); // // todo: andi 13/12/13: it would be simpler to bound the values instead of reinitializing them imgView = new MainGameImageView(controlWidth, controlHeight, imageUtils.cropAndScale(imageName, state), state); List<Polygon> polygons = polygonInitFactory.getScenePolygonInitializer().initialzePolygons(state); imgView.resetPolygons(polygons); viewState.setState(EViewState.CITY); logger.debug("State of the port scene after : " + state); } private void setUpSeamapImageView() {
@Override protected Image call() throws Exception { updateTitle("Image Cache Loader"); //Check if matching Image is in cache Image image = getCachedImage(identifier); if(image != null) { if(image.getWidth() == identifier.getWidth() && image.getHeight() == identifier.getHeight()) { updateUsage(identifier); return image; } } //Create new Image image = new Image(identifier.getUrl(), false); image = ImageUtilities.fitInDimensionAndCutEdges(image, identifier.getWidth(), identifier.getHeight()); addToCache(identifier, image); return image; } };
public OpenPatricianLargeWaxButtonSkin(final OpenPatricianLargeWaxButton button) { super(button); InputStream is = getClass().getResourceAsStream("sealingWaxFlattend_long.png"); Image img = new Image(is); final ImageView imageView = new ImageView(img); final Label label = new Label(); label.textProperty().bind(button.textProperty()); label.idProperty().bind(button.idProperty()); label.getStyleClass().add("OpenPatricianLargeWaxButtonLabeled"); label.onMouseClickedProperty().bind(button.onActionProperty()); imageView.onMouseReleasedProperty().bind(button.onActionProperty()); StackPane stack = new StackPane(); stack.getChildren().addAll(imageView, label); Group group = new Group(stack); group.setManaged(false); button.setPrefHeight(img.getHeight()); button.setPrefWidth(img.getWidth()); getChildren().add(group); }
@Override public void bindViewSizeToParent() { container.setPrefWidth(imageProp.getValue().getWidth()); container.setPrefHeight(imageProp.getValue().getHeight()); photoImageView.fitHeightProperty().bind(container.heightProperty()); photoImageView.fitWidthProperty().bind(container.widthProperty()); }
public void updateShipPosition() { INavigableVessel vessel = control.getVessel(); final Point2D location = vessel.getLocation(); double x = location.getX() * control.scaleProperty().get(); double y = location.getY() * control.scaleProperty().get(); control.setLayoutX(x - shipIcon.getWidth() / 2); control.setLayoutY(y - shipIcon.getHeight() / 2); logger.trace("Update ship {} position to {},{} in view {},{}", vessel.getName(), vessel.getLocation().getX(), vessel.getLocation().getY(), control.getLayoutX(), control.getLayoutY()); }
private void updatePlaceholder(Node newView) { if (root.getWidth() > 0 && root.getHeight() > 0) { Image placeholderImage = root.snapshot(null, new WritableImage((int) root.getWidth(), (int) root.getHeight())); placeholder.setImage(placeholderImage); placeholder.setFitWidth(placeholderImage.getWidth()); placeholder.setFitHeight(placeholderImage.getHeight()); } else { placeholder.setImage(null); } placeholder.setVisible(true); placeholder.setOpacity(1.0); root.getChildren().setAll(placeholder); root.getChildren().add(newView); placeholder.toFront(); } }
private void setUpSeamapImageView() { IHumanPlayer player = viewState.getPlayer(); Image mapImage = imageUtils.createMapWithCities(map, player); final Font openPatrician18 = Font.font("OpenPatrician", 18); mapImage = imageUtils.addCityNames(map, mapImage, openPatrician18); Dimension2D origDim = new Dimension2D(mapImage.getWidth(), mapImage.getHeight()); double scale = controlHeight/origDim.getHeight(); Dimension2D targetDim = new Dimension2D(origDim.getWidth()*scale, origDim.getHeight()*scale); mapImage = imageUtils.scale(mapImage, targetDim, scale); Point2D coordinates = viewState.getCurrentCityProxy().get().getCity().getCoordinates(); coordinates = new Point2D(coordinates.getX() * scale, coordinates.getY() * scale); if (seaMapView == null) { seaMapView = (SeamapImageView) context.getBean("seamapImageView", new Object[]{mapImage, controlWidth, controlHeight, coordinates, scale}); } else { seaMapView.resetImage(mapImage,controlWidth, controlHeight, scale); } imgView = seaMapView; viewState.setState(EViewState.MAP); }