Java GDAL – Read PNG and JPEG Image with World File

gdalgeotiff-tiffgeotoolsjavapng

I have a program where given an image I want to read the coordinates for each pixel.
I have implemented the code if the given image is a TIFF image and it works fine. The code that gives me the object with the coordinates is as follow:

File f = new File("image.tiff");
GridCoverage2D image = new GeoTiffReader(f).read(new GeneralParameterValue[]{policy, gridsize, useJaiRead});
Rectangle2D bounds2D = image.getEnvelope2D().getBounds2D();
bounds2D.getCenterX();
GridGeometry2D geometry = image.getGridGeometry();

I want to try now to read the same image but in another format (JPEG and PNG).
I have downloaded the images and each has a world file (pgw/jpw) and an aux file.

How can I obtain the same output I have on the TIFF file for these formats?

I am new to Java and geotools so I am a little lost.

Best Answer

You need to add the world image plugin and everything should be fine with no changes.