The image file reader

The formats handled by the generic image file reader, which are GIF, PNG and JPEG, are supported by the Java™ Platform, Standard Edition. An image coded in one of these formats does not contain any geo-referencing information, so this information has to be known before loading this kind of image. This is also true for TIFF images that do not contain GeoTIFF tags. Below you can find a description of the IlvRasterBasicImageReader, the IlvImageReader class and IlvImageTileLoader class.

The IlvRasterBasicImageReader class

The IlvRasterBasicImageReader class is a GIF, JPG, PNG or TIFF reader that creates reprojectable, stylable, and pixel-on-demand images.

Creating an image reader

You need first to create an image reader, and add the image file to be read:
IlvRasterBasicImageReader imageReader = new IlvRasterBasicImageReader();
imageReader.addMap(gifFile);
As these images have no longitude or latitude information, you need to geo-reference this image. The easiest way to do this is to set the image bounds in longitude and latitude. This obviously works only for images that have a spatial coverage along lines of longitude and latitude. For advanced management of more complex images, the Map Builder provides an image transformation model that manages reprojection and image interpolation ( ImageControlModel class).
In the example below, you set the image to cover the entire earth:
imageReader.setImageBounds(0,-Math.PI,Math.PI/2,Math.PI,-Math.PI/2);

Creating a data source

Once you have created the reader, you need to create a data source, which should be integrated into the manager properties:
IlvMapDataSource imageDataSource = 
IlvRasterDataSourceFactory.buildTiledImageDataSource(manager,imageReader,true,t
rue,null);
IlvMapDataSourceModel dataSourceModel = 
IlvMapDataSourceProperty.GetMapDataSourceModel(manager);
dataSourceModel.insert(imageDataSource);

Reading the data

You can then start reading your data:
dataSourceModel.start();
Starting the data source creates the necessary tiled layers, tile managers and IlvRasterIcon instances to manage the pixel-on-demand feature and the progressive display of the new geo-referenced image.
You can also create a subsampled preview of an image, using code such as:
int iconWidth=imageReader.getRasterProperties(0).getNumColumns();
int iconHeight=imageReader.getRasterProperties(0).getNumLines();
Image image = 
Toolkit.getDefaultToolkit().createImage(iReader.getTileLoader(0).getScaledImage
Producer(subsampling, new IlvRect(0, 0, iconWidth, iconHeight)));

The IlvImageReader class

If you do not need image the reprojection, styling or pixel-on-demand features, but simply want to insert and geo-reference a single GIF, JPG or PNG image, you can use the IlvImageReader class.
Note
If you use this class, the images created are not compatible with the data source and map layer management.
This class implements the IlvMapFeatureIterator interface. It returns only one IlvMapFeature object, which is the image stored in the file.
The geometry of this map feature is of type IlvMapImage. The map feature has no attributes. To use this reader you have to provide a file name and the coordinates of this image.
// The image is known to be at 77 degrees 30 seconds east
// and 10 degrees north for the upper left corner. 
// Lower right corner is at 82 degrees 30 seconds east
// and 5 degrees north.
IlvCoordinate ul = new IlvCoordinate(77.5, 10);
IlvCoordinate lr = new IlvCoordinate(82.5, 5);
IlvImageReader reader = new IlvImageReader("image.jpg", ul, lr);
IlvMapFeature feature = reader.getNextFeature();
IlvFeatureRenderer renderer = reader.getDefaultFeatureRenderer();
// Image is known to be in the geographic coordinate system.
IlvCoordinateTransformation tr 
        = new IlvCoordinateTransformation(IlvGeographicCoordinateSystem.WGS84,
                                         IlvGeographicCoordinateSystem.WGS84,
                                         new IlvMapAffineTransform());
IlvGraphic g = renderer.makeGraphic(feature, tr);
manager.addObject(g, false);

The IlvImageTileLoader class

If you do not need image reprojection, styling or pixel-on-demand features, but have access to a set of images, you can use the IlvImageTileLoader class.
Note
If you use this class, the images created are not compatible with the data source and map layer management. This information is provided for compatibility with older versions of JViews.
This class is used to read a set of images that are part of a larger image. This tile loader allows an application to load only the images that are visible at a given time, each image corresponding to a tile. Each file must be named so that it is possible to construct its file name knowing the row index and column index of the corresponding tile. To use this tile loader, you must provide the information needed to reconstruct the file name for a given tile: a pattern that matches the file naming scheme and two formatting strings.
IlvImageTileLoader loader = new IlvImageTileLoader(String pattern,
                                                   String rowFormatString,
                                                   String colFormatString);
The pattern argument must contain one ‘%r’ and one ‘%c’ conversion specifier. The %r conversion specifier is used to convert the row index of the tile, and the %c conversion specifier is used to convert the column index of the tile. These conversion parameters are replaced accordingly with the rowFormatString and the colFormatString parameters. This format string is used to construct two java.text.DecimalFormat strings.