Краткий обзор
Image
class представляет графические изображения и используется для того, чтобы загрузить изображения из указанного URL.
Изображения могут быть изменены, поскольку они загружаются (например, чтобы уменьшить объем памяти, использованный изображением). Приложение может определить качество фильтрации используемого, масштабируясь, и сохранить ли формат изображения исходного изображения.
Используйте ImageView для того, чтобы вывести на экран изображения, загруженные этим class. То же самое Image
экземпляр может быть выведен на экран многократным ImageView
s.
Пример кода для того, чтобы загрузить изображения.
код:
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
}
производит:
Профиль: распространенный
Переменная Сводка
доступ | имя | ввести | Может Читать | Может Init | Может Записать | Значение по умолчанию | описание |
---|---|---|---|---|---|---|---|
общественность-init | backgroundLoading | Булев | ложь |
Указывает, используется ли изображение заполнителя, в то время как URL загружается в фоновом режиме. |
|||
считанный общественностью | ошибка | Булев | ложь |
Указывает, была ли ошибка обнаружена, загружая изображение. |
|||
общественность-init | height | Число | 0 |
height ограничивающего прямоугольника, в пределах которого исходное изображение изменяется по мере необходимости, чтобы соответствовать. height ограничивающего прямоугольника, в пределах которого исходное изображение изменяется по мере необходимости, чтобы соответствовать. Если установлено в значение width , height and preserveRatio attributes.0Profile: common |
|||
public | placeholder | Изображение | 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 |