Java 8 ImageReadParam - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ImageReadParam class.

This code example shows how to use the following methods:getSourceRegion, setSourceRegion
     *         <code>false</code> otherwise. 
     */ 
    static boolean checkEmptySourceRegion(final ImageReadParam readParameters,
            final Rectangle dimensions) {
        Utilities.ensureNonNull("readDimension", dimensions);
        Utilities.ensureNonNull("readP", readParameters);
        final Rectangle sourceRegion = readParameters.getSourceRegion();
        Rectangle.intersect(sourceRegion, dimensions, sourceRegion);
        if (sourceRegion.isEmpty())
            return true; 
        readParameters.setSourceRegion(sourceRegion);
        return false; 
    } 
 
    /** 
     * Checks that a {@link File} is a real file, exists and is readable. 
     *  
     * @param file 
     *            the {@link File} instance to check. Must not be null. 
     *  
6
CodeRank
This code example shows how to use the following methods:setSourceRegion
			 * 图片裁剪区域。Rectangle 指定了坐标空间中的一个区域,通过 Rectangle 对象 
			 * 的左上顶点的坐标(x,y)、宽度和高度可以定义这个区域。 
			 */ 
			Rectangle rect = new Rectangle(intX, intY, intWidth, intHeight);
			// 提供一个 BufferedImage,将其用作解码像素数据的目标。 
			param.setSourceRegion(rect);
			/** 
			 * 使用所提供的 ImageReadParam 读取通过索引 imageIndex 指定的对象,并将 它作为一个完整的 
			 * BufferedImage 返回。 
			 */ 
			BufferedImage bi = reader.read(0, param);
			// 保存新图片 
			ImageIO.write(bi, "jpg", new File(strDst));
		} finally { 
			if (is != null)
				is.close();
			if (iis != null)
				iis.close();
		} 
	} 
5
CodeRank
This code example shows how to use the following methods:getDestinationType, getDestination
This code example shows how to use the following methods:setSourceRegion
    public static void setup() throws FileNotFoundException {
        // Definition of the url 
        granuleUrl = TestData.url(ReadTypeTest.class, "img.tiff");
        // Definition of the parameters 
        readParameters = new TIFFImageReadParam();
        readParameters.setSourceRegion(new Rectangle(0, 0, 40, 20));
        // Definition of the rasterDimensions 
        rasterDimensions = new Rectangle(0, 0, 20, 20);
        // Wrong Raster Dimensions 
        rasterDimensionsWrong = new Rectangle(41, 21, 2, 2);
    } 
 
    @Test
    public void testJAIReadType() throws IOException {
        // Definition of the reader 
        ImageReader reader = new TIFFImageReaderSpi().createReaderInstance();
        FileImageInputStream in = new FileImageInputStream(DataUtilities.urlToFile(granuleUrl));
 
        try { 
            reader.setInput(in);
5
CodeRank
This code example shows how to use the following methods:getDestinationOffset, getSourceRegion, getSourceXSubsampling, getSourceYSubsampling, getSubsamplingXOffset
5
CodeRank
This code example shows how to use the following methods:getSourceRegion
            // factors are computed as the ratio between the cropped source 
            // region sizes and the read image sizes. The translate 
            // settings are represented by the offsets of the source region. 
            // 
            // // 
            final Rectangle sourceRegion = imageReadParam.getSourceRegion();
            final double scaleX = sourceRegion.width / (1.0 * ssWidth);
            final double scaleY = sourceRegion.height / (1.0 * ssHeight);
            final double translateX = sourceRegion.x;
            final double translateY = sourceRegion.y;
            return createCoverageFromImage(image, ConcatenatedTransform.create(
                    ProjectiveTransform.create(new AffineTransform(scaleX, 0,
                            0, scaleY, translateX, translateY)), raster2Model));
        } else { 
            // In case of no transformation is required (As an instance, 
            // when reading the whole image) 
            return createCoverageFromImage(image);
        } 
    } 
 
4
CodeRank
This code example shows how to use the following methods:setDestinationType
        ImageReaderBase.getDestination(param, TYPES.iterator(), 42, 1);
    } 
 
    @Test
    public void testGetDestinationParamGoodDestinationType() throws IIOException {
        ImageReadParam param = new ImageReadParam();
        param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_ARGB));
        BufferedImage destination = ImageReaderBase.getDestination(param, TYPES.iterator(), 6, 7);
        assertEquals(BufferedImage.TYPE_INT_ARGB, destination.getType());
        assertEquals(6, destination.getWidth());
        assertEquals(7, destination.getHeight());
    } 
 
    @Test
    public void testGetDestinationParamGoodDestinationTypeAlt() throws IIOException {
        ImageReadParam param = new ImageReadParam();
        // In essence, this is the same as TYPE_INT_ARGB 
        ImageTypeSpecifier type = ImageTypeSpecifier.createPacked(ColorSpace.getInstance(ColorSpace.CS_sRGB), 0xff0000, 0xff00, 0xff, 0xff000000, DataBuffer.TYPE_INT, false);
        param.setDestinationType(type);
        BufferedImage destination = ImageReaderBase.getDestination(param, TYPES.iterator(), 6, 7);
4
CodeRank
This code example shows how to use the following methods:setSourceSubsampling
            int subY = (int) Math.max(originalHeight / (double) (height * sampleFactor), 1.0);
 
            if (subX > 1 || subY > 1) {
                System.out.println("subX: " + subX);
                System.out.println("subY: " + subY);
                pParam.setSourceSubsampling(subX, subY, subX > 1 ? subX / 2 : 0, subY > 1 ? subY / 2 : 0);
            } 
        } 
 
        BufferedImage image = pReader.read(0, pParam);
 
        System.out.println("image: " + image);
 
        int algorithm = BufferedImage.SCALE_DEFAULT;
        if (pArgs.length > 4) {
            if ("smooth".equals(pArgs[4].toLowerCase())) {
                algorithm = BufferedImage.SCALE_SMOOTH;
            } 
            else if ("fast".equals(pArgs[4].toLowerCase())) {
                algorithm = BufferedImage.SCALE_FAST;
4
CodeRank
This code example shows how to use the following methods:setDestination
 
        // Create dest image with same data, except properties... 
        BufferedImage dest = new BufferedImage(
                image.getColorModel(), image.getRaster(), image.getColorModel().isAlphaPremultiplied(), null
        ); 
        ImageReadParam param = new ImageReadParam();
        param.setDestination(dest);
 
        assertHotSpot(getTestData().get(0), param, new Point(15, 15));
    } 
 
    // TODO: Test cursor is transparent 
 
    @Test
    @Ignore("Known issue") 
    @Override 
    public void testNotBadCaching() throws IOException {
        super.testNotBadCaching(); 
    } 
} 
4
CodeRank
This code example shows how to use the following methods:setSourceRegion, setSourceSubsampling
        if (ECWP.equalsIgnoreCase(ECWPSkipTest))
            return; 
 
        final ImageReader mReader = new ECWImageReaderSpi().createReaderInstance();
        final ECWPImageInputStream ecwp = new ECWPImageInputStream(ECWP);
        final ImageReadParam param = new ImageReadParam();
        param.setSourceSubsampling(1, 1, 0, 0);
        param.setSourceRegion(new Rectangle(1000, 1000, 2000, 2000));
        final int imageIndex = 0;
 
        mReader.setInput(ecwp);
        final RenderedImage image = mReader.readAsRenderedImage(imageIndex, param);
        if (TestData.isInteractiveTest()) 
            Viewer.visualizeAllInformation(image, ECWP);
        mReader.dispose();
    } 
     
    @Test
    public void emptyTest(){ 
         
4
CodeRank
See Code Examples for Java 8 ImageReadParam Methods: