当前位置: 首页>>代码示例>>Java>>正文


Java RenderedOp.getWidth方法代码示例

本文整理汇总了Java中javax.media.jai.RenderedOp.getWidth方法的典型用法代码示例。如果您正苦于以下问题:Java RenderedOp.getWidth方法的具体用法?Java RenderedOp.getWidth怎么用?Java RenderedOp.getWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.media.jai.RenderedOp的用法示例。


在下文中一共展示了RenderedOp.getWidth方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resizeImageAsJPG

import javax.media.jai.RenderedOp; //导入方法依赖的package包/类
/**
 * This method takes in an image as a byte array (currently supports GIF, JPG, PNG and
 * possibly other formats) and
 * resizes it to have a width no greater than the pMaxWidth parameter in pixels.
 * It converts the image to a standard
 * quality JPG and returns the byte array of that JPG image.
 *
 * @param pImageData
 *                the image data.
 * @param pMaxWidth
 *                the max width in pixels, 0 means do not scale.
 * @return the resized JPG image.
 * @throws IOException
 *                 if the image could not be manipulated correctly.
 */
public byte[] resizeImageAsJPG(byte[] pImageData, int pMaxWidth) throws IOException {
    InputStream imageInputStream = new ByteArrayInputStream(pImageData);
    // read in the original image from an input stream
    SeekableStream seekableImageStream = SeekableStream.wrapInputStream(imageInputStream, true);
    RenderedOp originalImage = JAI.create(JAI_STREAM_ACTION, seekableImageStream);
    ((OpImage) originalImage.getRendering()).setTileCache(null);
    int origImageWidth = originalImage.getWidth();
    // now resize the image
    double scale = 1.0;
    if (pMaxWidth > 0 && origImageWidth > pMaxWidth) {
        scale = (double) pMaxWidth / originalImage.getWidth();
    }
    ParameterBlock paramBlock = new ParameterBlock();
    paramBlock.addSource(originalImage); // The source image
    paramBlock.add(scale); // The xScale
    paramBlock.add(scale); // The yScale
    paramBlock.add(0.0); // The x translation
    paramBlock.add(0.0); // The y translation

    RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY);

    RenderedOp resizedImage = JAI.create(JAI_SUBSAMPLE_AVERAGE_ACTION, paramBlock, qualityHints);

    // lastly, write the newly-resized image to an output stream, in a specific encoding
    ByteArrayOutputStream encoderOutputStream = new ByteArrayOutputStream();
    JAI.create(JAI_ENCODE_ACTION, resizedImage, encoderOutputStream, JAI_ENCODE_FORMAT_JPEG, null);
    // Export to Byte Array
    byte[] resizedImageByteArray = encoderOutputStream.toByteArray();
    return resizedImageByteArray;
}
 
开发者ID:aysenurbilgin,项目名称:cww_framework,代码行数:47,代码来源:ImageResize.java

示例2: createImage

import javax.media.jai.RenderedOp; //导入方法依赖的package包/类
@Override
protected RenderedImage createImage(int level) {
    final List<RenderedImage> tileImages = Collections.synchronizedList(new ArrayList<>(numXTiles * numYTiles));
    double factorX = 1.0 / Math.pow(2, level);
    double factorY = 1.0 / Math.pow(2, level);
    for (int x = 0; x < numYTiles; x++) {
        for (int y = 0; y < numXTiles; y++) {
            PlanarImage opImage;
            try {
                opImage = createTileImage(x, y, level);
                if (opImage != null) {
                    opImage = TranslateDescriptor.create(opImage,
                                                         (float) (y * tileWidth * factorX),
                                                         (float) (x * tileHeight * factorY),
                                                         Interpolation.getInstance(Interpolation.INTERP_NEAREST),
                                                         null);
                }
            } catch (IOException ex) {
                opImage = ConstantDescriptor.create((float) tileWidth, (float) tileHeight, new Number[]{0}, null);
            }
            tileImages.add(opImage);
        }
    }
    if (tileImages.isEmpty()) {
        logger.warning("No tile images for mosaic");
        return null;
    }

    //if (imageLayout == null) {
        imageLayout = new ImageLayout();
        imageLayout.setMinX(0);
        imageLayout.setMinY(0);
        imageLayout.setTileWidth(JAI.getDefaultTileSize().width);
        imageLayout.setTileHeight(JAI.getDefaultTileSize().height);
        imageLayout.setTileGridXOffset(0);
        imageLayout.setTileGridYOffset(0);
        //imageLayout.setSampleModel(ImageUtils.createSingleBandedSampleModel(dataType, imageWidth, imageHeight));
        //imageLayout.setColorModel(ImageUtils.create8BitGreyscaleColorModel());
    //}

    RenderedOp mosaicOp = MosaicDescriptor.create(tileImages.toArray(new RenderedImage[tileImages.size()]),
                                                  MosaicDescriptor.MOSAIC_TYPE_OVERLAY,
                                                  null, null, null, null,
                                                  new RenderingHints(JAI.KEY_IMAGE_LAYOUT, imageLayout));
    int fittingRectWidth = scaleValue(imageWidth, level);
    int fittingRectHeight = scaleValue(imageHeight, level);

    Rectangle fitRect = new Rectangle(0, 0, fittingRectWidth, fittingRectHeight);
    final Rectangle destBounds = DefaultMultiLevelSource.getLevelImageBounds(fitRect, Math.pow(2.0, level));

    BorderExtender borderExtender = BorderExtender.createInstance(BorderExtender.BORDER_COPY);

    if (mosaicOp.getWidth() < destBounds.width || mosaicOp.getHeight() < destBounds.height) {
        int rightPad = destBounds.width - mosaicOp.getWidth();
        int bottomPad = destBounds.height - mosaicOp.getHeight();
        mosaicOp = BorderDescriptor.create(mosaicOp, 0, rightPad, 0, bottomPad, borderExtender, null);
    }

    return mosaicOp;
}
 
开发者ID:senbox-org,项目名称:s2tbx,代码行数:61,代码来源:MosaicMultiLevelSource.java

示例3: createImage

import javax.media.jai.RenderedOp; //导入方法依赖的package包/类
@Override
protected RenderedImage createImage(int level) {
    ArrayList<RenderedImage> tileImages = new ArrayList<>();

    List<String> tiles = sceneDescription.getTileIds().stream().filter(x -> x.contains(tileBandInfo.detectorId)).collect(Collectors.toList());


    TileLayout thisBandTileLayout = this.tileBandInfo.getImageLayout();
    TileLayout productTileLayout = getConfig().getTileLayout(getProductResolution());
    float layoutRatioX = (float) productTileLayout.width / thisBandTileLayout.width;
    float layoutRatioY = (float) productTileLayout.height / thisBandTileLayout.height;


    for (String tileId : tiles) {
        int tileIndex = sceneDescription.getTileIndex(tileId);
        Rectangle tileRectangle = sceneDescription.getTileRectangle(tileIndex);

        PlanarImage opImage = createL1bTileImage(tileId, level);
        {

            double factorX = 1.0 / (Math.pow(2, level) * layoutRatioX);
            double factorY = 1.0 / (Math.pow(2, level) * layoutRatioY);

            opImage = TranslateDescriptor.create(opImage,
                                                 (float) Math.floor((tileRectangle.x * factorX)),
                                                 (float) Math.floor((tileRectangle.y * factorY)),
                                                 Interpolation.getInstance(Interpolation.INTERP_NEAREST), null);

            logger.log(Level.parse(S2Config.LOG_SCENE), String.format("Translate descriptor: %s", ToStringBuilder.reflectionToString(opImage)));
        }

        logger.log(Level.parse(S2Config.LOG_SCENE), String.format("opImage added for level %d at (%d,%d) with size (%d,%d)%n", level, opImage.getMinX(), opImage.getMinY(), opImage.getWidth(), opImage.getHeight()));
        tileImages.add(opImage);
    }

    if (tileImages.isEmpty()) {
        logger.warning("No tile images for mosaic");
        return null;
    }

    ImageLayout imageLayout = new ImageLayout();
    imageLayout.setMinX(0);
    imageLayout.setMinY(0);
    imageLayout.setTileWidth(S2Config.DEFAULT_JAI_TILE_SIZE);
    imageLayout.setTileHeight(S2Config.DEFAULT_JAI_TILE_SIZE);
    imageLayout.setTileGridXOffset(0);
    imageLayout.setTileGridYOffset(0);

    RenderedOp mosaicOp = MosaicDescriptor.create(tileImages.toArray(new RenderedImage[tileImages.size()]),
                                                  MosaicDescriptor.MOSAIC_TYPE_OVERLAY,
                                                  null, null, new double[][]{{1.0}}, new double[]{S2Config.FILL_CODE_MOSAIC_BG},
                                                  new RenderingHints(JAI.KEY_IMAGE_LAYOUT, imageLayout));


    int fitRectWidht = (int) (sceneDescription.getSceneEnvelope().getWidth() /
            (layoutRatioX * getProductResolution().resolution));
    int fitRectHeight = (int) (sceneDescription.getSceneEnvelope().getHeight() /
            (layoutRatioY * getProductResolution().resolution));

    Rectangle fitRect = new Rectangle(0, 0, fitRectWidht, fitRectHeight);
    final Rectangle destBounds = DefaultMultiLevelSource.getLevelImageBounds(fitRect, Math.pow(2.0, level));

    BorderExtender borderExtender = BorderExtender.createInstance(BorderExtender.BORDER_COPY);

    if (mosaicOp.getWidth() < destBounds.width || mosaicOp.getHeight() < destBounds.height) {
        int rightPad = destBounds.width - mosaicOp.getWidth();
        int bottomPad = destBounds.height - mosaicOp.getHeight();
        SystemUtils.LOG.log(Level.parse(S2Config.LOG_SCENE), String.format("Border: (%d, %d), (%d, %d)", mosaicOp.getWidth(), destBounds.width, mosaicOp.getHeight(), destBounds.height));

        mosaicOp = BorderDescriptor.create(mosaicOp, 0, rightPad, 0, bottomPad, borderExtender, null);
    }

    logger.log(Level.parse(S2Config.LOG_SCENE), String.format("mosaicOp created for level %d at (%d,%d) with size (%d, %d)%n", level, mosaicOp.getMinX(), mosaicOp.getMinY(), mosaicOp.getWidth(), mosaicOp.getHeight()));

    return mosaicOp;
}
 
开发者ID:senbox-org,项目名称:s2tbx,代码行数:77,代码来源:Sentinel2L1BProductReader.java


注:本文中的javax.media.jai.RenderedOp.getWidth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。