2

I am using following code to save a Goverage2D to JPG:

File tmpJpgFile = File.createTempFile("temp", ".jpg");
Iterator<ImageWriter> writers = ImageIO.getImageWritersBySuffix("jpg");
ImageWriter writer = null;
while(writers.hasNext()) {
   writer=writers.next();
   break;
}
if (writer!=null) {
   writer.setOutput(new ImageOutputStreamAdapter(new FileOutputStream(tmpJpgFile)));
   writer.write(croppedCoverage.getRenderedImage());
   FileRawData fileRawData = new FileRawData(tmpJpgFile, "jpg", outputMimeType);
   tmpJpgFile.deleteOnExit();
   return fileRawData;
} else {
   throw new WPSException("No JPG Writer available to generate image.");                
}

I get the following error:

Process failed during execution javax.imageio.IIOException: Illegal band size: should be 0 < size <= 8

The same GridCoverage2D gets written in a GeoTiff flawlessly.

Has this omething to do with the fact the Coverage has just one band?

Here from gdalinfo of geotiff export:

Metadata:
  AREA_OR_POINT=Area
  TIFFTAG_RESOLUTIONUNIT=1 (unitless)
  TIFFTAG_XRESOLUTION=1
  TIFFTAG_YRESOLUTION=1
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (  441180.000, 5013630.000) (  8d15' 0.43"E, 45d16'25.35"N)
..
Center      (  441295.000, 5013500.000) (  8d15' 5.76"E, 45d16'21.17"N)
Band 1 Block=16x32 Type=Float32, ColorInterp=Gray
  Min=-0.214 Max=0.195
  Minimum=-0.214, Maximum=0.195, Mean=0.043, StdDev=0.048
  Metadata:
    STATISTICS_MAXIMUM=0.19480518996716
    STATISTICS_MEAN=0.042965890258674
    STATISTICS_MINIMUM=-0.21431475877762
    STATISTICS_STDDEV=0.048457298863482
  • two things - please add gdalinfo output for the input file, and also write out which JPG writer you are using – Ian Turton May 10 at 8:18
  • I have no idea about what JPG writer I am using: the code is wrapped in a GeoServerProcess for exposing a WPS, hance is using all Geoserver/Geotools dependencies as well as GDAL 1.9.2 through the GeoServer " ImageI/O-Ext GDAL Coverage Extension " – mcfoi May 10 at 8:22
  • add System.out.println(writer); instead of the break statement. I get com.sun.imageio.plugins.jpeg.JPEGImageWriter@47289387 which works for me – Ian Turton May 10 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.