Overview
The Image
class represents graphical images and is used for loading
images from a specified URL.
Images can be resized as they are loaded (for example to reduce the amount of memory consumed by the image). The application can specify the quality of filtering used when scaling, and whether or not to preserve the original image's aspect ratio.
Use ImageView for displaying images loaded with this
class. The same Image
instance can be displayed by multiple
ImageView
s.
Example code for loading images.
the code:
import javafx.scene.image.Image;
// load an image in background, displaying a placeholder while it's loading
// (assuming there's an ImageView node somewhere displaying this image)
var image1 = Image {
url: "{__DIR__}flower.png"
backgroundLoading: true
placeholder: Image {
url: "{__DIR__}placeholder.png"
}
}
// load an image and resize it to 100x150 without preserving its original
// aspect ratio
var image2 = Image {
url: "{__DIR__}flower.png"
width: 100
height: 150
preserveRatio: false
}
// load an image and resize it to width of 100 while preserving its
// original aspect ratio, using faster filtering method
var image3 = Image {
url: "{__DIR__}flower.png"
width: 100
smooth: false
}
// load an image and resize it only in one dimension, to the height of 100 and
// the original width, without preserving original aspect ratio
var image4 = Image {
url: "{__DIR__}flower.png"
height: 100
preserveRatio: false
}
produces:
Profile: common
Variable Summary
access | name | type | Can Read | Can Init | Can Write | Default Value | description |
---|---|---|---|---|---|---|---|
public-init | backgroundLoading | Boolean | false |
Indicates whether the placeholder image is used while the URL is loaded in the background. |
|||
public-read | error | Boolean | false |
Indicates whether an error was detected while loading an image. |
|||
public-init | height | Number | 0 |
The height of the bounding box within which the source image is resized as necessary to fit. The height of the bounding box within which the source image is
resized as necessary to fit. If set to a value width , height and preserveRatio
attributes.0Profile: common |
|||
public | placeholder | Image | null |
The placeholder image which is used when backgroundLoading is set to true and the URL is loaded in the background. |
|||
public-init | preserveRatio | Boolean | false |
Indicates whether to preserve the aspect ratio of the original image
when scaling to fit the image within the bounding box provided by
Indicates whether to preserve the aspect ratio of the original image
when scaling to fit the image within the bounding box provided by
true , it affects the dimensions of this Image
in the following way:
width and height may be different from the
initially set values if they needed to be adjusted to preserve aspect
ratio.
If unset or set to false , it affects the dimensions of this
ImageView in the following way:
Profile: common |
|||
public-read | progress | Number | 0 |
The approximate percentage of image's loading that has been completed. |
|||
public-init | smooth | Boolean | true |
Indicates whether to use a better quality filtering algorithm or a faster
one when scaling this image to fit within the
bounding box provided by Indicates whether to use a better quality filtering algorithm or a faster
one when scaling this image to fit within the
bounding box provided by
If not initialized or set to Profile: common |
|||
public-init | url | String | empty string |
The string representing the URL to use in fetching the pixel data. |
|||
public-init | width | Number | 0 |
The width of the bounding box within which the source image is resized as necessary to fit. The width of the bounding box within which the source image is
resized as necessary to fit. If set to a value width , height and preserveRatio
attributes.0Profile: common |