JavaFX ImageView Set the image path

tags: JavaFX series tutorial  javafx  imageview  java

JavaFX ImageView dynamically set image path:

FXML file:

<AnchorPane stylesheets="@/css/ModelView.css" style="-fx-background-color: #1E3434;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.demo.controller.ModelViewController">
   <children>
		<StackPane fx:id="left" minHeight="535.0" minWidth="450.0">
			<children>
				 <VBox alignment="CENTER" spacing="50.0">
					 <children>
						 <ImageView fitWidth="350.0" fx:id="dynamic"/>
					 </children>
				 </VBox>
			</children>
		 </StackPane>
    </children>
</AnchorPane>

Controller:

@Slf4j
@FXMLController
public class ModelViewController implements Initializable {

	@FXML
    private ImageView dynamic;
	
	/**
     * Initialization loading
     * @param location
     * @param resources
     */
    @Override
    public void initialize(URL location, ResourceBundle resources) {
        File file = new File("src/main/resources/images/1.png");
        String string = file.toURI().toString();
        Image image = new Image(string);
        dynamic.setImage(image);
	}
}

effect:

JavaFX ImageView

note:

The path address problem of the picture, using the relative address:

src/main/resources/images/1.png

 

Intelligent Recommendation

Imageview set image zoom interception method

Today I found that the image zoom and capture features that come with imageview are so powerful: Setting android:scaleType="centerCrop" will make the image fill the area you want to fill. Wh...

Javafx set image transparency (saturation, brightness is the same)

The window interface code is as follows: Set the image transparency code: (You may want to try to modify the color or transparency of each pixel and write it to the screen. But note that the Image obj...

Set the image adaptive size in ImageView and set the maximum width and height

Set the image adaptive size in ImageView, and set the maximum width and height. When the width and height of the image is greater than the set maximum value, the width and height are the set maximum....

About: ImageView loading image Path is no problem, the picture is not displayed

source: Let me talk about how to get the path to the local image. ImageView displays the image by loading the path. Of course, you also need to add permissions in the AndroidManifest.xml file. But eve...

Why can't the image set by ImageView cover the entire control

Problem Description An ImageView was added to the top of a bullet frame, and the picture was set, but there were blanks on both sides and not full. Corresponding source code: analysis The occurrence o...

More Recommendation

Android several ways to set the image of ImageView (src and background are different)

Foreword: The imageview courseware is familiar to everyone, but when setting up the image, it is easy to confuse src and background. As the name suggests:src is the foreground, and background is the b...

Android Set Watermark Image in ImageView in the lower right corner

Automatically add custom watermarks to the lower right corner of the picture after taking pictures View turn Bitmap Picture Calling mode`, ivpreviw is an ImageView image control, LLVIEW is the LINEARL...

JavaFx+JFoenix completely solves the problem of Image reading path

JavaFx+JFoenix completely solves the problem of Image reading path Article Directory JavaFx+JFoenix completely solves the problem of Image reading path 1. JavaFx Image class loading file three strateg...

(ImageView) - ImageView set fill mode

ImageView set the fill mode Set ImageView fill mode on the premise that the use ofsrcAs set image source, otherwise it will lead the way to set the picture fill void context. scaleType = "matrix&...

Android - known image path or uri, ImageView loads this image, Bitmap rotates image

Description: Know the image path filepath or uri, use ImageView to load filepath, and rotate Bitmap image at the same time Code: 1, the known picture path 2, known picture uri 3, picture bitmap rotati...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top