JavaFX: Bringing Rich Experiences To All the Screens Of Your Life

Profile: desktop, common

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 ImageViews.

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

accessnametypeCan ReadCan InitCan WriteDefault Valuedescription
public-initbackgroundLoadingBooleanfalse

Indicates whether the placeholder image is used while the URL is loaded in the background.

public-readerrorBooleanfalse

Indicates whether an error was detected while loading an image.

public-initheightNumber0

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 <= 0, then the intrinsic height of the image will be used.

See preserveRatio for information on interaction between image's view width, height and preserveRatio attributes.

0

Profile: common

&nbsp;
publicplaceholderImagenull

The placeholder image which is used when backgroundLoading is set to true and the URL is loaded in the background.

public-initpreserveRatioBooleanfalse

Indicates whether to preserve the aspect ratio of the original image when scaling to fit the image within the bounding box provided by width and height.

Indicates whether to preserve the aspect ratio of the original image when scaling to fit the image within the bounding box provided by width and height.

If set to true, it affects the dimensions of this Image in the following way:

  • If only width is set, height is scaled to preserve ratio
  • If only height is set, width is scaled to preserve ratio
  • If both are set, they both may be scaled to get the best fit in a width by height rectangle while preserving the original aspect ratio
The reported 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:
  • If only width is set, the image's width is scaled to match and height is unchanged;
  • If only height is set, the image's height is scaled to match and height is unchanged;
  • If both are set, the image is scaled to match both.

false

Profile: common

&nbsp;
public-readprogressNumber0

The approximate percentage of image's loading that has been completed.

public-initsmoothBooleantrue

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 width and height.

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 width and height.

If not initialized or set to true a better quality filtering will be used, otherwise a faster but lesser quality filtering will be used.

true

Profile: common

&nbsp;
public-initurlStringempty string

The string representing the URL to use in fetching the pixel data.

public-initwidthNumber0

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 <= 0, then the intrinsic width of the image will be used.

See preserveRatio for information on interaction between image's view width, height and preserveRatio attributes.

0

Profile: common

&nbsp;

Inherited Variables

Script Function Summary

public impl_fromPlatformImage(image: java.lang.Object) : Image
Parameters
image
Returns
Image
&nbsp;

Function Summary

public cancel() : Void

Cancels the background loading of this image.

Cancels the background loading of this image.

Has no effect if this image isn't loaded in background or if loading has already completed.

Profile: common

&nbsp;

Inherited Functions




Spec-Zone.ru - all specs in one place