Spec-Zone .ru
спецификации, руководства, описания, API
|
public class Image
extends java.lang.Object
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.
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) Image image1 = new Image("flower.png", true); // load an image and resize it to 100x150 without preserving its original // aspect ratio Image image2 = new Image("flower.png", 100, 150, false, false); // load an image and resize it to width of 100 while preserving its // original aspect ratio, using faster filtering method Image image3 = new Image("flower.png", 100, 0, false, 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 Image image4 = new Image("flower.png", 0, 100, false, false);
Type | Property and Description |
---|---|
ReadOnlyBooleanProperty |
error
Indicates whether an error was detected while loading an image.
|
ReadOnlyDoubleProperty |
height
The image height or
0 if the image loading fails. |
ReadOnlyDoubleProperty |
progress
The approximate percentage of image's loading that
has been completed.
|
ReadOnlyDoubleProperty |
width
The image width or
0 if the image loading fails. |
Constructor and Description |
---|
Image(java.io.InputStream is)
Construct an
Image which pixels are loaded from the specified
input stream. |
Image(java.io.InputStream is,
double requestedWidth,
double requestedHeight,
boolean preserveRatio,
boolean smooth)
Construct a new
Image with the specified parameters. |
Image(java.lang.String url)
Construct an
Image which pixels are loaded from the specified
url. |
Image(java.lang.String url,
boolean backgroundLoading)
Construct a new
Image with the specified parameters. |
Image(java.lang.String url,
double requestedWidth,
double requestedHeight,
boolean preserveRatio,
boolean smooth)
Construct a new
Image with the specified parameters. |
Image(java.lang.String url,
double requestedWidth,
double requestedHeight,
boolean preserveRatio,
boolean smooth,
boolean backgroundLoading)
Construct a new
Image with the specified parameters. |
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Cancels the background loading of this image.
|
ReadOnlyBooleanProperty |
errorProperty()
Indicates whether an error was detected while loading an image.
|
double |
getHeight()
The image height or
0 if the image loading fails. |
double |
getProgress()
The approximate percentage of image's loading that
has been completed.
|
double |
getRequestedHeight()
Gets the height of the bounding box within which the source image is
resized as necessary to fit.
|
double |
getRequestedWidth()
Gets the width of the bounding box within which the source image is
resized as necessary to fit.
|
double |
getWidth()
The image width or
0 if the image loading fails. |
ReadOnlyDoubleProperty |
heightProperty()
The image height or
0 if the image loading fails. |
boolean |
isBackgroundLoading()
Indicates whether the image is being loaded in the background.
|
boolean |
isError()
Indicates whether an error was detected while loading an image.
|
boolean |
isPreserveRatio()
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 . |
boolean |
isSmooth()
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 . |
ReadOnlyDoubleProperty |
progressProperty()
The approximate percentage of image's loading that
has been completed.
|
ReadOnlyDoubleProperty |
widthProperty()
The image width or
0 if the image loading fails. |
getProgress()
0
if the image loading fails. While the image
is being loaded it is set to 0
.getWidth()
0
if the image loading fails. While the image
is being loaded it is set to 0
.getHeight()
isError()
public Image(java.lang.String url)
Image
which pixels are loaded from the specified
url.url
- the string representing the URL to use in fetching the pixel
datapublic Image(java.lang.String url, boolean backgroundLoading)
Image
with the specified parameters.url
- the string representing the URL to use in fetching the pixel
databackgroundLoading
- indicates whether the image
is being loaded in the backgroundpublic Image(java.lang.String url, double requestedWidth, double requestedHeight, boolean preserveRatio, boolean smooth)
Image
with the specified parameters.url
- the string representing the URL to use in fetching the pixel
datarequestedWidth
- the image's bounding box widthrequestedHeight
- the image's bounding box heightpreserveRatio
- indicates whether to preserve the aspect ratio of
the original image when scaling to fit the image within the
specified bounding boxsmooth
- indicates whether to use a better quality filtering
algorithm or a faster one when scaling this image to fit within
the specified bounding boxpublic Image(java.lang.String url, double requestedWidth, double requestedHeight, boolean preserveRatio, boolean smooth, boolean backgroundLoading)
Image
with the specified parameters.url
- the string representing the URL to use in fetching the pixel
datarequestedWidth
- the image's bounding box widthrequestedHeight
- the image's bounding box heightpreserveRatio
- indicates whether to preserve the aspect ratio of
the original image when scaling to fit the image within the
specified bounding boxsmooth
- indicates whether to use a better quality filtering
algorithm or a faster one when scaling this image to fit within
the specified bounding boxbackgroundLoading
- indicates whether the image
is being loaded in the backgroundpublic Image(java.io.InputStream is)
Image
which pixels are loaded from the specified
input stream.is
- the stream from which to load the imagepublic Image(java.io.InputStream is, double requestedWidth, double requestedHeight, boolean preserveRatio, boolean smooth)
Image
with the specified parameters.is
- the stream from which to load the imagerequestedWidth
- the image's bounding box widthrequestedHeight
- the image's bounding box heightpreserveRatio
- indicates whether to preserve the aspect ratio of
the original image when scaling to fit the image within the
specified bounding boxsmooth
- indicates whether to use a better quality filtering
algorithm or a faster one when scaling this image to fit within
the specified bounding boxpublic final double getProgress()
public final ReadOnlyDoubleProperty progressProperty()
getProgress()
public final double getRequestedWidth()
<= 0
, then the
intrinsic width of the image will be used.
See preserveRatio
for information on interaction between image's
requestedWidth
, requestedHeight
and preserveRatio
attributes.public final double getRequestedHeight()
<= 0
, then the
intrinsic height of the image will be used.
See preserveRatio
for information on interaction between image's
requestedWidth
, requestedHeight
and preserveRatio
attributes.public final double getWidth()
0
if the image loading fails. While the image
is being loaded it is set to 0
.public final ReadOnlyDoubleProperty widthProperty()
0
if the image loading fails. While the image
is being loaded it is set to 0
.getWidth()
public final double getHeight()
0
if the image loading fails. While the image
is being loaded it is set to 0
.public final ReadOnlyDoubleProperty heightProperty()
0
if the image loading fails. While the image
is being loaded it is set to 0
.getHeight()
public final boolean isPreserveRatio()
width
and height
.
If set to true
, it affects the dimensions of this Image
in the following way:
width
is set, height is scaled to preserve ratio
height
is set, width is scaled to preserve ratio
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:
width
is set, the image's width is scaled to
match and height is unchanged;
height
is set, the image's height is scaled to
match and height is unchanged;
public final boolean isSmooth()
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.
width
and height
.public final boolean isBackgroundLoading()
public final boolean isError()
public final ReadOnlyBooleanProperty errorProperty()
isError()
public void cancel()
Has no effect if this image isn't loaded in background or if loading has already completed.
Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. Use is subject to