|
| 1 | +package org.esa.beam; |
| 2 | + |
| 3 | +import com.bc.ceres.core.ProgressMonitor; |
| 4 | +import org.esa.beam.framework.dataio.ProductIO; |
| 5 | +import org.esa.beam.framework.datamodel.Band; |
| 6 | +import org.esa.beam.framework.datamodel.ImageInfo; |
| 7 | +import org.esa.beam.framework.datamodel.Product; |
| 8 | +import org.esa.beam.util.ProductUtils; |
| 9 | + |
| 10 | +import javax.imageio.ImageIO; |
| 11 | +import java.awt.image.BufferedImage; |
| 12 | +import java.io.File; |
| 13 | +import java.io.IOException; |
| 14 | + |
| 15 | +/** |
| 16 | + * @author Marco Peters |
| 17 | + */ |
| 18 | +public class ImageExportMain { |
| 19 | + |
| 20 | + public static void main(String[] args) { |
| 21 | + |
| 22 | + String[] rgbBandNames = new String[3]; |
| 23 | + rgbBandNames[0] = "radiance_3"; |
| 24 | + rgbBandNames[1] = "radiance_2"; |
| 25 | + rgbBandNames[2] = "radiance_1"; |
| 26 | + |
| 27 | + try { |
| 28 | + Product inputProduct = ProductIO.readProduct(args[0]); |
| 29 | +// Product inputProduct = ProductIO.readProduct("G:\\EOData\\ALOS\\AVNIR2\\AV2_MMC_FR__0000091001\\VOL-ALAV2A038712630-O1B2G_U"); |
| 30 | + System.out.println(inputProduct); |
| 31 | + Band[] produtBands = inputProduct.getBands(); |
| 32 | + Band[] rgbBands = new Band[3]; |
| 33 | + |
| 34 | + int n = 0; |
| 35 | + for (Band band : produtBands) { |
| 36 | + |
| 37 | + if (band.getName().equals(rgbBandNames[0])) { |
| 38 | + rgbBands[0] = band; |
| 39 | + } else if (band.getName().equals(rgbBandNames[1])) { |
| 40 | + rgbBands[1] = band; |
| 41 | + } else if (band.getName().equals(rgbBandNames[2])) { |
| 42 | + rgbBands[2] = band; |
| 43 | + } |
| 44 | + |
| 45 | + n = n + 1; |
| 46 | + } |
| 47 | + |
| 48 | + ImageInfo outImageInfo = ProductUtils.createImageInfo(rgbBands, true, ProgressMonitor.NULL); |
| 49 | + BufferedImage outImage = ProductUtils.createRgbImage(rgbBands, outImageInfo, ProgressMonitor.NULL); |
| 50 | + |
| 51 | + final File outputFile = new File(inputProduct.getName() + ".png"); |
| 52 | + ImageIO.write(outImage, "PNG", outputFile); |
| 53 | + |
| 54 | + } catch (IOException e) { |
| 55 | + System.err.println("Error: " + e.getMessage()); |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | +} |
0 commit comments