Game Development Reference
In-Depth Information
specify the scaling algorithm (quality) as well. All URLs that are supported by the
java.net.URL class are supported. This means that you can load images from the Inter-
net ( www.servername.com/image.png ) ; from the OS (file:image.png); or from
the JAR file, using a forward slash (/image.png).
The Java class hierarchy for the Image class starts with the java.lang.Object mas-
ter class and uses this class to create the javafx.scene.image.Image class. As Figure
6-4 shows (l. 9), Image is contained in the JavaFX image package, just like the
ImageView class, and uses the following class hierarchy structure:
java.lang.Object
> javafx.scene.image. Image
The Image class supplies six different (overloaded) Image() constructor methods.
These take anything from a simple URL to a set of parameter values specifying the
URL , width , height , aspectRatioLock , smoothing , and preload options. These
should be specified in that order within the constructor method, as you will soon see,
when you write an Image() constructor using the most complicated of all the construct-
or methods, which has the following format:
Image(String url , double requestedWidth , double
requestedHeight , boolean preserveRatio, boolean smooth,
boolean backgroundLoading )
The simple constructor for an Image object specifies only the URL and uses the
following format:
Image(String url )
If you want to load an image and also have the constructor method scale the image
to a different width and height (usually, this is smaller, to save memory), while locking
(preserving) the aspect ratio, using the highest-quality resampling (smooth-pixel scal-
ing), that Image object constructor uses the following format:
Image(String url , double scaleWidth , double scaleHeight ,
boolean preserveAspect , boolean smooth )
If you want to load an image in the background ( asynchronously ), using its “nat-
ive,” or physical, resolution and native aspect ratio, the Image() constructor uses the
following format:
Search WWH ::




Custom Search