Example usage for java.awt.image RenderedImage getHeight

List of usage examples for java.awt.image RenderedImage getHeight

Introduction

In this page you can find the example usage for java.awt.image RenderedImage getHeight.

Prototype

int getHeight();

Source Link

Document

Returns the height of the RenderedImage.

Usage

From source file:org.apache.fop.visual.BitmapComparator.java

/**
 * Loads an image from a URL//from w  ww  . j  a v a 2 s . com
 * @param bitmapFile the bitmap file
 * @return the bitmap as BufferedImage
 */
public static BufferedImage getImage(File bitmapFile) {
    try {
        InputStream in = new java.io.FileInputStream(bitmapFile);
        try {
            in = new java.io.BufferedInputStream(in);

            ImageTagRegistry reg = ImageTagRegistry.getRegistry();
            Filter filt = reg.readStream(in);
            if (filt == null) {
                return null;
            }

            RenderedImage red = filt.createDefaultRendering();
            if (red == null) {
                return null;
            }

            BufferedImage img = new BufferedImage(red.getWidth(), red.getHeight(), BufferedImage.TYPE_INT_ARGB);
            red.copyData(img.getRaster());
            return img;
        } finally {
            IOUtils.closeQuietly(in);
        }
    } catch (IOException e) {
        return null;
    }
}

From source file:org.apache.xmlgraphics.ps.PSImageUtils.java

private static ColorModel populateImageDictionary(ImageEncodingHelper helper, PSDictionary imageDict) {
    RenderedImage img = helper.getImage();
    String w = Integer.toString(img.getWidth());
    String h = Integer.toString(img.getHeight());
    imageDict.put("/ImageType", "1");
    imageDict.put("/Width", w);
    imageDict.put("/Height", h);

    ColorModel cm = helper.getEncodedColorModel();

    boolean invertColors = false;
    String decodeArray = getDecodeArray(cm.getNumComponents(), invertColors);
    int bitsPerComp = cm.getComponentSize(0);

    // Setup scanning for left-to-right and top-to-bottom
    imageDict.put("/ImageMatrix", "[" + w + " 0 0 " + h + " 0 0]");

    if ((cm instanceof IndexColorModel)) {
        IndexColorModel im = (IndexColorModel) cm;
        int c = im.getMapSize();
        int hival = c - 1;
        if (hival > 4095) {
            throw new UnsupportedOperationException("hival must not go beyond 4095");
        }/* w  ww . ja  v  a2s.co m*/
        bitsPerComp = im.getPixelSize();
        int ceiling = ((int) Math.pow(2, bitsPerComp)) - 1;
        decodeArray = "[0 " + ceiling + "]";
    }
    imageDict.put("/BitsPerComponent", Integer.toString(bitsPerComp));
    imageDict.put("/Decode", decodeArray);
    return cm;
}

From source file:org.esa.nest.gpf.ERSCalibrator.java

private RenderedImage removeFactorsApplied(final RenderedImage downSampledImage,
        final Rectangle sourceTileRectangle) {

    final int sx0 = sourceTileRectangle.x;
    final int w = downSampledImage.getWidth();
    final int h = downSampledImage.getHeight();
    final double[] array = new double[h * w];
    //final Raster data = downSampledImage.getData();
    final Raster data = downSampledImage.getData(new Rectangle(0, 0, w, h));
    double sigma;
    int k = 0;//from   ww w.ja v a2 s. c o  m
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {

            sigma = data.getSampleDouble(x, y, 0);

            if (antennaPatternCorrectionFlag) {
                sigma *= antennaPatternGain[sx0 + x * blockWidth];
            }

            if (rangeSpreadingLossCompFlag) {
                sigma /= rangeSpreadingLoss[sx0 + x * blockWidth];
            }

            if (!isERS1Mission) {
                sigma /= replicaPulseVariationsCorrectionFactor;
            }

            array[k++] = Math.sqrt(sigma);
        }
    }

    return createRenderedImage(array, w, h);
}

From source file:org.esa.nest.gpf.ERSCalibrator.java

private double[][] computeADCPowerLossValue(final RenderedImage squaredImage,
        final TileDescriptionFlags tileDescriptionFlags) {

    final int delH = (windowHeight / 2) / blockHeight;
    final int delW = (windowWidth / 2) / blockWidth;

    int x0 = 0;//from w w  w.  j av  a 2 s . c om
    int y0 = 0;
    int w = squaredImage.getWidth();
    int h = squaredImage.getHeight();
    if (tileDescriptionFlags.adcSourceTileTopExtFlag) {
        y0 = delH;
        h -= delH;
    }
    if (tileDescriptionFlags.adcSourceTileBottomExtFlag) {
        h -= delH;
    }
    if (h <= 0)
        h = 1;

    if (tileDescriptionFlags.adcSourceTileLeftExtFlag) {
        x0 = delW;
        w -= delW;
    }
    if (tileDescriptionFlags.adcSourceTileRightExtFlag) {
        w -= delW;
    }
    if (w <= 0)
        w = 1;

    double[][] adcPowerLoss = new double[h][w];

    Raster data = squaredImage.getData();

    double dn;
    for (int y = y0; y < y0 + h; y++) {
        for (int x = x0; x < x0 + w; x++) {
            dn = data.getSampleDouble(x, y, 0);
            if (isERS1Mission) {
                adcPowerLoss[y - y0][x - x0] = getPowerLossValue(dn, appendixF1);
            } else {
                adcPowerLoss[y - y0][x - x0] = getPowerLossValue(dn, appendixF2);
            }
        }
    }
    /*
    for (int x = 0; x < w; x++) {
    System.out.print(adcPowerLoss[25][x] + ",");
    }
    System.out.println();
    */
    return adcPowerLoss;
}

From source file:org.esa.nest.gpf.ERSCalibrator.java

private static void outputRealImage(final RenderedImage I, final int startIdx, final int endIdx) {

    final Raster data = I.getData();
    final double[] real = data.getSamples(0, 0, I.getWidth(), I.getHeight(), 0, (double[]) null);

    for (int i = startIdx; i <= endIdx; i++) {
        System.out.print(real[i] + ",");
    }/* ww w  . j a  v  a2 s  .com*/
    System.out.println();
}

From source file:org.esa.s2tbx.dataio.jp2.internal.JP2TileOpImage.java

private void computeRectIndirect(WritableRaster dest, Rectangle destRect) {
    try {//from w w w  .j a  v a 2s.  co m
        Path tile = decompressTile(tileIndex, getLevel());
        RenderedImage readTileImage = null;
        if (tile != null) {
            try (ImageReader imageReader = new ImageReader(tile)) {
                final DataBuffer dataBuffer = dest.getDataBuffer();
                int tileWidth = this.getTileWidth();
                int tileHeight = this.getTileHeight();
                final int fileTileX = destRect.x / tileLayout.tileWidth;
                final int fileTileY = destRect.y / tileLayout.tileHeight;
                int fileTileOriginX = destRect.x - fileTileX * tileLayout.tileWidth;
                int fileTileOriginY = destRect.y - fileTileY * tileLayout.tileHeight;
                Rectangle fileTileRect = tileDims.get(tile);
                if (fileTileRect == null) {
                    fileTileRect = new Rectangle(0, 0, imageReader.getImageWidth(),
                            imageReader.getImageHeight());
                    tileDims.put(tile, fileTileRect);
                }
                if (fileTileOriginX == 0 && tileLayout.tileWidth == tileWidth && fileTileOriginY == 0
                        && tileLayout.tileHeight == tileHeight
                        && tileWidth * tileHeight == dataBuffer.getSize()) {
                    readTileImage = imageReader.read();
                } else {
                    final Rectangle tileRect = new Rectangle(fileTileOriginX, fileTileOriginY, tileWidth,
                            tileHeight);
                    final Rectangle intersection = fileTileRect.intersection(tileRect);
                    if (!intersection.isEmpty()) {
                        readTileImage = imageReader.read(intersection);
                    }
                }
                if (readTileImage != null) {
                    Raster readBandRaster = readTileImage.getData().createChild(0, 0, readTileImage.getWidth(),
                            readTileImage.getHeight(), 0, 0, new int[] { bandIndex });
                    dest.setDataElements(dest.getMinX(), dest.getMinY(), readBandRaster);
                }
            } catch (IOException e) {
                logger.severe(e.getMessage());
            }
        }
    } catch (IOException e) {
        logger.severe(e.getMessage());
    }
}

From source file:org.gbif.portal.util.image.ImageUtils.java

/**
 * Return true if the URL resolves to an image (rather than e.g. a web
 * page or application launcher.//from   ww w.  j  a v  a  2  s. c  o m
 *
 * @param url
 * @return image width and height in a int array
 */
public static int[] findImageDimensions(String url) {
    try {
        RenderedImage image = ImageIO.read(new URL(url));
        return new int[] { image.getWidth(), image.getHeight() };
    } catch (Exception e) {
        logger.error("Problem loading image from url: " + url);
        logger.error(e.getMessage(), e);
        return null;
    }
}

From source file:org.gbif.portal.util.image.ImageUtils.java

/**
 * Scale an image to the required size/* w  w w  . j  a v  a 2s .  co m*/
 *
 * @param image
 * @param width
 * @param height
 */
public static void scaleImage(RenderedImage image, int width, int height) {

    int originalWidth = image.getWidth();
    int originalHeight = image.getHeight();

    Float heightScale = 1.0f;
    Float widthScale = 1.0f;

    if (originalHeight > height) {
        heightScale = (float) height / (float) originalHeight;
    }
    if (originalWidth > width) {
        widthScale = (float) width / (float) originalWidth;
    }

    if (heightScale < widthScale) {
        widthScale = heightScale;
    } else {
        heightScale = widthScale;
    }
    image = JAI.create("scale", image, widthScale, heightScale);
}

From source file:org.geoserver.wcs.GetCoverageTest.java

/**
 * This tests just ended up throwing an exception as the coverage being encoded
 * was too large due to a bug in the scales estimation
 * /* ww  w . ja  va 2s  .c  om*/
 * @throws Exception
 */
@Test
public void testRotatedPost() throws Exception {
    String request = "<GetCoverage xmlns=\"http://www.opengis.net/wcs/1.1.1\" xmlns:gml=\"http://www.opengis.net/gml\"\n"
            + "             xmlns:ows11=\"http://www.opengis.net/ows/1.1\"\n"
            + "             xmlns:ows=\"http://www.opengis.net/ows/1.1\"\n"
            + "             xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \r\n" + //
            "             xmlns:wcs=\"http://schemas.opengis.net/wcs/1.1.1\"\n"
            + "             xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n" + "             service=\"WCS\"\n"
            + "             version=\"1.1.1\"\n"
            + "             xsi:schemaLocation=\"http://www.opengis.net/wcs/1.1.1 http://schemas.opengis.net/wcs/1.1.1/wcsAll.xsd\">\n"
            + "   <ows11:Identifier>RotatedCad</ows11:Identifier>\n" + "   <DomainSubset>\n"
            + "      <ows11:BoundingBox crs=\"urn:ogc:def:crs:OGC:1.3:CRS84\">\n"
            + "         <ows11:LowerCorner>7.7634301664746515 45.14713380418506</ows11:LowerCorner>\n"
            + "         <ows11:UpperCorner>7.764350661575157 45.14763319238466</ows11:UpperCorner>\n"
            + "      </ows11:BoundingBox>\n" + "   </DomainSubset>\n" + "   <Output format=\"image/tiff\"/>\n"
            + "</GetCoverage>";

    MockHttpServletResponse response = postAsServletResponse("wcs", request);

    // parse the multipart, check there are two parts
    Multipart multipart = getMultipart(response);
    assertEquals(2, multipart.getCount());
    BodyPart coveragePart = multipart.getBodyPart(1);
    assertEquals("image/tiff", coveragePart.getContentType());
    assertEquals("<theCoverage>", coveragePart.getHeader("Content-ID")[0]);

    // make sure we can read the coverage back
    ImageReader reader = ImageIO.getImageReadersByFormatName("tiff").next();
    reader.setInput(ImageIO.createImageInputStream(coveragePart.getInputStream()));
    RenderedImage image = reader.read(0);

    // check the image is suitably small (without requiring an exact size)
    assertTrue(image.getWidth() < 1000);
    assertTrue(image.getHeight() < 1000);
}

From source file:org.geoserver.wcs.GetCoverageTest.java

/**
 * This tests just ended up throwing an exception as the coverage being encoded
 * was too large due to a bug in the scales estimation
 * /*from  w  w w. j  a v a  2s. c o m*/
 * @throws Exception
 */
@Test
public void testRotatedGet() throws Exception {
    String request = "wcs?&service=WCS&request=GetCoverage&version=1.1.1&identifier=RotatedCad&BoundingBox=7.7634071540971386,45.14712131948007,7.76437367395267,45.14764567708965,urn:ogc:def:crs:OGC:1.3:CRS84&Format=image/tiff";
    MockHttpServletResponse response = getAsServletResponse(request);

    // parse the multipart, check there are two parts
    Multipart multipart = getMultipart(response);
    assertEquals(2, multipart.getCount());
    BodyPart coveragePart = multipart.getBodyPart(1);
    assertEquals("image/tiff", coveragePart.getContentType());
    assertEquals("<theCoverage>", coveragePart.getHeader("Content-ID")[0]);

    // make sure we can read the coverage back
    ImageReader reader = ImageIO.getImageReadersByFormatName("tiff").next();
    reader.setInput(ImageIO.createImageInputStream(coveragePart.getInputStream()));
    RenderedImage image = reader.read(0);

    // check the image is suitably small (without requiring an exact size)
    assertTrue(image.getWidth() < 1000);
    assertTrue(image.getHeight() < 1000);
}