Class Image

java.lang.Object
javafx.scene.image.Image
Direct Known Subclasses:
WritableImage

public class Image extends Object
The Image class represents graphical images and is used for loading images from a specified URL.

Supported image formats are:

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.

If a URL string is passed to a constructor, it be any of the following:

  1. the name of a resource that can be resolved by the context ClassLoader for this thread
  2. a file path that can be resolved by File
  3. a URL that can be resolved by URL and for which a protocol handler exists

The RFC 2397 "data" scheme for URLs is supported in addition to the protocol handlers that are registered for the application. If a URL uses the "data" scheme, the data must be base64-encoded and the MIME type must be a subtype of the image type. The MIME type must match the image format of the data contained in the URL. In case of a mismatch between MIME type and image format, the image will be loaded if the image format can be determined by JavaFX, and a warning will be logged.

Use ImageView for displaying images loaded with this class. The same Image instance can be displayed by multiple ImageViews.

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)
// The image is located in default package of the classpath
Image image1 = new Image("/flower.png", true);

// load an image and resize it to 100x150 without preserving its original
// aspect ratio
// The image is located in my.res package of the classpath
Image image2 = new Image("my/res/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
// The image is downloaded from the supplied URL through http protocol
Image image3 = new Image("http://sample.com/res/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
// The image is located in the current working directory
Image image4 = new Image("file:flower.png", 0, 100, false, false);

Since:
JavaFX 2.0