Java 8 ImageReader - 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 ImageReader class.

This code example shows how to use the following methods:dispose, getDefaultReadParam, read, setInput
			imageInputStream = createImageInputStream(inputMessage.getBody());
			MediaType contentType = inputMessage.getHeaders().getContentType();
			Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(contentType.toString());
			if (imageReaders.hasNext()) {
				imageReader = imageReaders.next();
				ImageReadParam irp = imageReader.getDefaultReadParam();
				process(irp);
				imageReader.setInput(imageInputStream, true);
				return imageReader.read(0, irp);
			} 
			else { 
				throw new HttpMessageNotReadableException(
						"Could not find javax.imageio.ImageReader for Content-Type [" + contentType + "]");
			} 
		} 
		finally { 
			if (imageReader != null) {
				imageReader.dispose();
			} 
			if (imageInputStream != null) {

8
CodeRank
This code example shows how to use the following methods:dispose, getDefaultReadParam, read, setInput
                throw new IOException("The image-based media type " + mediaType + "is not supported for reading");
            } 
            ImageReader reader = readers.next();
 
            ImageInputStream in = ImageIO.createImageInputStream(entityStream);
            reader.setInput(in, true, true);
            BufferedImage bi = reader.read(0, reader.getDefaultReadParam());
            in.close();
            reader.dispose();
            return bi;
        } else { 
            return ImageIO.read(entityStream);
        } 
    } 
 
    @Override 
    public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
        return RenderedImage.class.isAssignableFrom(type);
    } 
 
7
CodeRank
This code example shows how to use the following methods:dispose, getHeight, getMinIndex, getWidth, setInput
 
                if (readers.hasNext()) {
                    ImageReader reader = readers.next();
 
                    try { 
                        reader.setInput(image);
                        int index = reader.getMinIndex();
                        put("width", reader.getWidth(index));
                        put("height", reader.getHeight(index));
 
                    } finally { 
                        reader.dispose();
                    } 
                } 
 
            } finally { 
                image.close();
            } 
 
        } catch (IOException error) {
6
CodeRank
This code example shows how to use the following methods:dispose, getHeight, getMinIndex, getWidth, setInput
	    if (iter.hasNext()) { 
	        ImageReader reader = iter.next(); 
	        ImageInputStream stream = null;
	        try {  
	            stream = new FileImageInputStream(new File(path)); 
	            reader.setInput(stream); 
	            int width = reader.getWidth(reader.getMinIndex()); 
	            int height = reader.getHeight(reader.getMinIndex()); 
	            result = new Dimension(width, height);
	        } finally { 
	        	if(stream != null){
	        		stream.close();
	        	} 
	            reader.dispose(); 
	        }  
	    } else {  
	        assertFalse("No reader for gif", true);
	    }  
	    return result; 
	}  
6
CodeRank
This code example shows how to use the following methods:dispose, getNumImages, setInput
        ImageReader r = null;
        try { 
            is = getBinaryInputStream(response);
            iis = ImageIO.createImageInputStream(is);
            r = ImageIO.getImageReadersBySuffix("gif").next();
            r.setInput(iis);
            return r.getNumImages(true);
        } finally { 
            if (r != null) { 
                r.dispose();
            } 
            if (iis != null) {
                iis.close();
            } 
            if (is != null) {
                try { is.close(); } catch (IOException ignore) {}
            } 
           
        } 
    } 
6
CodeRank
This code example shows how to use the following methods:dispose, getHeight, getWidth, setInput
	public ScalableComponent getComponent() { 
		return bitmapViewerComponent;
	} 
 
	public ScalableComponent createViewer(URI uri, float zoom)
			throws MalformedURLException, IOException {
		bitmapViewerComponent = new BitmapViewerComponent(uri);
		bitmapViewerComponent.setFinalViewerSize(zoom);
		return bitmapViewerComponent;
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:getHeight, getImageTypes, getTileHeight, getTileWidth, getWidth
     * @param reader an istance of {@link ImageReader} 
     * @throws IOException in case an error occurs 
     */ 
    protected void setLayout(ImageReader reader) throws IOException {
 
        Utilities.ensureNonNull("reader", reader);
        // save ImageLayout 
        ImageLayout2 layout = new ImageLayout2();
        ImageTypeSpecifier its = reader.getImageTypes(0).next();
        layout.setColorModel(its.getColorModel()).setSampleModel(its.getSampleModel());
        layout.setMinX(0).setMinY(0).setWidth(reader.getWidth(0)).setHeight(reader.getHeight(0));
        layout.setTileGridXOffset(0).setTileGridYOffset(0).setTileWidth(reader.getTileWidth(0))
                .setTileHeight(reader.getTileHeight(0));
        setlayout(layout);
    } 
 
    /** 
     * Set the provided layout for this {@link GridCoverage2DReader}- 
     *  
     * @param layout the {@link ImageLayout} to set. It must be nont null 
6
CodeRank
This code example shows how to use the following methods:dispose, read, setInput
                reader = newSpi.createReaderInstance();
                if (source instanceof FileResource) { 
                    // file 
                    stream= new FileImageInputStreamExtImpl(((FileResource)source).getFile());
                    // Image reading 
                    reader.setInput(stream);
                    return reader.read(0);                    
                } else { 
                    // create a stream and move on 
                    source=((Resource)source).getInputStream(); 
                } 
                 
                // Check if the input object is an InputStream 
                if (source instanceof InputStream) {
                    // Use of the ImageInputStreamAdapter 
                    if (isAggressiveInputStreamSupported()) { 
                        stream = new ImageInputStreamAdapter((InputStream) source);
                    } else { 
                        stream = new MemoryCacheImageInputStream((InputStream) source);
                    } 

6
CodeRank
This code example shows how to use the following methods:sleep, addIIOReadProgressListener, getDefaultReadParam, read, reset
        this.action.setTarget(reader);
    } 
 
    public void doTest() { 
        try { 
            reader.addIIOReadProgressListener(this);
            iis = ImageIO.createImageInputStream(file);
            reader.setInput(iis);
            ImageReadParam p = reader.getDefaultReadParam();
            Thread.sleep(70);
            BufferedImage res = reader.read(0, p);
            Thread.sleep(70);
        } catch (Exception e) {
            /* 
             * we do expect that concurrent attempt to dispose this 
             * instance of image reader will be blocked. So, this image 
             * should be read sucessfuly. Otherwise, something went wrong 
             * and we need to report test failure. 
             */ 
            throw new RuntimeException("Test FAILED", e);

6
CodeRank
This code example shows how to use the following methods:dispose, getDefaultReadParam, readAll, setInput
        if (!iter.hasNext()) {
            return null; 
        } 
 
        ImageReader reader = (ImageReader) iter.next();
        ImageReadParam param = reader.getDefaultReadParam();
        reader.setInput(stream, true, true);
        IIOImage iioImage = reader.readAll(0, param);
        stream.close();
        reader.dispose();
        return iioImage;
    } 
 
 
    /** 
     * Writes an image using an arbitrary <code>ImageWriter</code> that supports the given format to a 
     * <code>File</code>.  If there is already a <code>File</code> present, its contents are discarded. 
     * 
     * @param iioImage   the image data to be written. 
     * @param formatName a <code>String</code> containg the informal name of the format. 
6
CodeRank
See Code Examples for Java 8 ImageReader Methods: