Package javax.imageio

Examples of javax.imageio.ImageReader


            final Iterator<ImageReader> jpegReaderIt =
                        ImageIO.getImageReadersByFormatName("jpeg");
            IIOException lastIioEx = null;
            while (jpegReaderIt.hasNext()) {
                try {
                    final ImageReader jpegReader = jpegReaderIt.next();
                    jpegReader.setInput(ImageIO.createImageInputStream(
                            new ByteBufferInputStream(jpegData)), true, false);
                    return readImage(jpegReader, readParam);
                } catch (IIOException e) {
                    // its most likely complaining about an unsupported image
                    // type; hopefully the next image reader will be able to
View Full Code Here


    try {
      inputStream = url.openStream();
      in = ImageIO.createImageInputStream(inputStream);
      final Iterator<ImageReader> readers = ImageIO.getImageReaders(in);
      if (readers.hasNext()) {
        final ImageReader reader = readers.next();
        try {
          reader.setInput(in);
          return new Dimension(reader.getWidth(0), reader.getHeight(0));
        }
        finally {
          reader.dispose();
        }
      }
      else {
        throw new IOException("can not create image");
      }
View Full Code Here

     * 来自: http://stackoverflow.com/questions/2408613/problem-reading-jpeg-image-using-imageio-readfile-file
     *
     * */
    private static BufferedImage readJpeg(InputStream in) throws IOException {
        Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("JPEG");
        ImageReader reader = null;
        while(readers.hasNext()) {
            reader = (ImageReader)readers.next();
            if(reader.canReadRaster()) {
                break;
            }
        }
        ImageInputStream input = ImageIO.createImageInputStream(in);
        reader.setInput(input);
        //Read the image raster
        Raster raster = reader.readRaster(0, null);
        BufferedImage image = createJPEG4(raster);
        File tmp = File.createTempFile("nutz.img", "jpg"); //需要写到文件,然后重新解析哦
        writeJpeg(image, tmp, 1);
        return read(tmp);
    }
View Full Code Here

            Iterator<ImageReader> jpegReaderIt = ImageIO.getImageReadersByFormatName("jpeg");
            IIOException lastIioEx = null;
            while (jpegReaderIt.hasNext()) {
                try {
                    final ImageReader jpegReader = jpegReaderIt.next();
                    jpegReader.setInput(ImageIO.createImageInputStream(
                            new ByteBufferInputStream(jpegData)), true, false);
                    try {
                        return readImage(jpegReader, readParam);
                    } catch (Exception e) {
                        if (e instanceof IIOException) {
View Full Code Here

      buf.get(input);
      Iterator<ImageReader> readers = ImageIO.getImageReadersByMIMEType("image/jpeg2000");
      if (readers.hasNext() == false) {
        throw new PDFParseException("JPXDecode failed. No reader available");
      }
      ImageReader reader = readers.next();
      reader.setInput(new MemoryCacheImageInputStream(new ByteArrayInputStream(input)));
      BufferedImage bimg = reader.read(0);
      return bimg;
    } catch (IOException e) {
            throw new PDFParseException("JPXDecode failed", e);
    }
View Full Code Here

    }

    private int getApp14AdobeTransform(byte[] bytes)
    {
        int transformType = 0;
        ImageReader reader = null;
        ImageInputStream input = null;
        try
        {
            input = ImageIO.createImageInputStream(new ByteArrayInputStream(bytes));
            Iterator<ImageReader> readers = ImageIO.getImageReaders(input);
            if (readers == null || !readers.hasNext())
            {
                throw new RuntimeException("No ImageReaders found");
            }
            reader = (ImageReader) readers.next();
            reader.setInput(input);
            IIOMetadata meta = reader.getImageMetadata(0);
            if (meta != null)
            {
                Node tree = meta.getAsTree("javax_imageio_jpeg_image_1.0");
                NodeList children = tree.getChildNodes();
                for (int i=0;i<children.getLength();i++)
                {
                    Node markerSequence = children.item(i);
                    if ("markerSequence".equals(markerSequence.getNodeName()))
                    {
                        NodeList markerSequenceChildren = markerSequence.getChildNodes();
                        for (int j=0;j<markerSequenceChildren.getLength();j++)
                        {
                            Node child = markerSequenceChildren.item(j);
                            if ("app14Adobe".equals(child.getNodeName()) && child.hasAttributes())
                            {
                                NamedNodeMap attribs = child.getAttributes();
                                Node transformNode = attribs.getNamedItem("transform");
                                transformType = Integer.parseInt(transformNode.getNodeValue());
                                break;
                            }
                        }
                    }
                }
            }
        }
        catch(IOException exception)
        {
           
        }
        finally
        {
            try
            {
                if (input != null)
                {
                    input.close();
                }
            }
            catch (IOException exception)
            {
                // swallow the exception
            }
            if (reader != null)
            {
                reader.dispose();
            }
        }
        return transformType;
    }
View Full Code Here

            input.close();
            throw new RuntimeException("No ImageReaders found");
        }
        // read the raster information only
        // avoid to access the meta information
        ImageReader reader = (ImageReader) readers.next();
        reader.setInput(input);
        Raster raster = reader.readRaster(0, reader.getDefaultReadParam());
        input.close();
        reader.dispose();
        return raster;
    }
View Full Code Here

                         */
                        try {
                                if (f.exists() && fileMode.contains("r")) {
                                        ImageInputStream iis = ImageIO.createImageInputStream(f);
                                        for (Iterator<ImageReader> itr = ImageIO.getImageReaders(iis); itr.hasNext() && mime == null;) {
                                                ImageReader r = itr.next();
                                                synchronized (fileFilters) {
                                                        for (ImagePluginDescriptor ipd : fileFilters) {
                                                                Properties p = ipd.p;
                                                                if (p.getProperty(ImagePluginDescriptor.get.support.toString()) != null) {
                                                                        if (p.getProperty(ImagePluginDescriptor.get.support.toString()).contains(fileMode)) {
                                                                                for (String m : r.getOriginatingProvider().getMIMETypes()) {
                                                                                        if (m.equals(p.getProperty(ImagePluginDescriptor.get.mime.toString()))) {
                                                                                                mime = m;
                                                                                                break;
                                                                                        }
                                                                                }
View Full Code Here

                        sprint = "Warning ! ImageIO doesn't have any cache enabled. This may result in unexpected behaviours. (ImageIO.setUseCache())" + net.sf.jiga.xtended.kernel.Console.newLine;
                }
                String[] mimes = ImageIO.getReaderMIMETypes();
                for (int i = 0; i < mimes.length; i++) {
                        for (Iterator<ImageReader> it = ImageIO.getImageReadersByMIMEType(mimes[i]); it.hasNext();) {
                                ImageReader r = it.next();
                                sprint += "ImageReader " + mimes[i] + " : " + r.toString() + net.sf.jiga.xtended.kernel.Console.newLine;
                        }
                }
                mimes = ImageIO.getWriterMIMETypes();
                for (int i = 0; i < mimes.length; i++) {
                        String ctype = _getCompressionType(mimes[i], _getBufferedType(mimes[i]));
View Full Code Here

        private transient ImageCollectionRenderer renderer = this;

        private JComponent makeThumbnailStore(File image, final String key, String mime, Map<String, Serializable> attrs) throws IOException {
                String m = _getImageMimeType(image, "r");
                Sprite picture = null;
                ImageReader r = null;
                try {
                        Map<String, Object> s = Sprite._loadImage(image, false, m, Sprite.MODE_JAVA2D | Sprite.MODE_TILE, _getBufferedType(m), false);
                        r = (ImageReader) s.get("reader");
                        picture = new Sprite(image, m, new Dimension(r.getWidth(0), r.getHeight(0)), true);
                } catch (Exception ex) {
                        if (JXAenvUtils._debug) {
                                ex.printStackTrace();
                        }
                        IOException e = new IOException(ex.getMessage());
                        e.initCause(ex);
                        throw e;
                } finally {
                        ((ImageInputStream) r.getInput()).flush();
                        r.dispose();
                        ((ImageInputStream) r.getInput()).close();
                        picture.setStoreMode(Sprite.MODE_JAVA2D | Sprite.MODE_TILE);
                        return makeThumbnailStore(picture, key, mime, attrs);
                }

        }
View Full Code Here

TOP

Related Classes of javax.imageio.ImageReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.