Package javax.imageio

Examples of javax.imageio.ImageReader


 
  protected static void readJPEG(byte[] data,BufferedImage dest) throws IOException {
    ByteArrayInputStream in = new ByteArrayInputStream(data);
    ImageInputStream stream = ImageIO.createImageInputStream(in);
    Iterator iter = ImageIO.getImageReaders(stream);
    ImageReader reader = (ImageReader)iter.next();
    if(reader==null)
      throw new UnsupportedOperationException("This image is unsupported.");
    reader.setInput(stream,false);
   
    ImageReadParam param = reader.getDefaultReadParam();
    param.setDestination(dest);
    reader.read(0,param);
  }
View Full Code Here


        .createImageInputStream(new FileInputStream(image));
    Iterator iter = ImageIO.getImageReaders(stream);
    if (!iter.hasNext()) {
      return null;
    }
    ImageReader reader = (ImageReader) iter.next();
    stream.close();
    return reader.getFormatName();
  }
View Full Code Here

    */
   public static ImageReader getImageReaderByMediaType(MediaType mediaType)
   {
      Iterator<ImageReader> readers = ImageIO.getImageReadersByMIMEType(mediaType.toString());

      ImageReader reader = null;
      while (readers.hasNext())
      {
         reader = (ImageReader) readers.next();
      }

View Full Code Here

        assertEquals(format, result.getBarcodeFormat());
    }
   
    private void checkType(File file, String type) throws IOException {
        ImageInputStream iis = ImageIO.createImageInputStream(file);
        ImageReader reader = ImageIO.getImageReaders(iis).next();
        String format = reader.getFormatName();
        assertEquals(type, format.toUpperCase());
    }
View Full Code Here

  public void consumeOutput(InputStream pInputStream) throws IOException {
    ImageInputStream iis = ImageIO.createImageInputStream(pInputStream);
    if (iis != null) {
      Iterator<ImageReader> iter = ImageIO.getImageReaders(iis);
      if (iter.hasNext()) {
  ImageReader reader = iter.next();
  reader.setInput(iis);
  iImage = reader.read(0);
  iis.close();
  reader.dispose();
      } else {
  throw new IllegalStateException("no ImageReader for given format");
      }
    } else {
      throw new IllegalStateException("failed to create ImageInputStream");
View Full Code Here

        {
            ImageInputStream imgInput = ImageIO.createImageInputStream(new ByteArrayInputStream(buffer));
            Iterator it = ImageIO.getImageReaders(imgInput);           
            while (it.hasNext())
            {
                ImageReader reader = (ImageReader) it.next();
                reader.setInput(imgInput, true);
                setWidth(reader.getWidth(0));
                setHeight(reader.getHeight(0));
                _type = "image/" + reader.getFormatName();
            }
        } catch (IOException e)
        {
            try
            {
View Full Code Here

        if (type != null) {
            try {
                Iterator<ImageReader> iterator =
                    ImageIO.getImageReadersByMIMEType(type);
                if (iterator.hasNext()) {
                    ImageReader reader = iterator.next();
                    reader.setInput(ImageIO.createImageInputStream(
                            new CloseShieldInputStream(stream)));
                    metadata.set("height", Integer.toString(reader.getHeight(0)));
                    metadata.set("width", Integer.toString(reader.getWidth(0)));
                    reader.dispose();
                }
            } catch (IIOException e) {
                throw new TikaException(type + " parse error", e);
            }
        }
View Full Code Here

    public Object getContent(DataSource ds) throws IOException {
        Iterator i = ImageIO.getImageReadersByMIMEType(ds.getContentType());
        if (!i.hasNext()) {
            throw new UnsupportedDataTypeException();
        }
        ImageReader reader = (ImageReader) i.next();
        return reader.read(0);
    }
View Full Code Here

            Iterator iter = ImageIO.getImageReaders(imgStream);
            if (!iter.hasNext()) {
                log.error("No ImageReader found.");
                return false;
            }
            ImageReader reader = (ImageReader)iter.next();
            ImageReadParam param = reader.getDefaultReadParam();
            reader.setInput(imgStream, true, false);
            BufferedImage imageData = reader.read(0, param);
           
            //Read image resolution
            IIOMetadata iiometa = reader.getImageMetadata(0);
            if (iiometa != null && iiometa.isStandardMetadataFormatSupported()) {
                Element metanode = (Element)iiometa.getAsTree("javax_imageio_1.0");
                Element dim = getChild(metanode, "Dimension");
                if (dim != null) {
                    Element child;
                    child = getChild(dim, "HorizontalPixelSize");
                    if (child != null) {
                        this.dpiHorizontal = UnitConv.IN2MM
                                / Float.parseFloat(child.getAttribute("value"));
                    }
                    child = getChild(dim, "VerticalPixelSize");
                    if (child != null) {
                        this.dpiVertical = UnitConv.IN2MM
                                / Float.parseFloat(child.getAttribute("value"));
                    }
                }
            }
            imgStream.close();
            reader.dispose();
           
            this.height = imageData.getHeight();
            this.width = imageData.getWidth();

            ColorModel cm = imageData.getColorModel();
View Full Code Here

        Source src = session.needSource(info.getOriginalURI());
        ImageInputStream imgStream = ImageUtil.needImageInputStream(src);
        try {
            Iterator iter = ImageIO.getImageReaders(imgStream);
            while (iter.hasNext()) {
                ImageReader reader = (ImageReader)iter.next();
                try {
                    imgStream.mark();
                    ImageReadParam param = reader.getDefaultReadParam();
                    reader.setInput(imgStream, false, ignoreMetadata);
                    final int pageIndex = ImageUtil.needPageIndexFromURI(info.getOriginalURI());
                    try {
                        if (ImageFlavor.BUFFERED_IMAGE.equals(this.targetFlavor)) {
                            imageData = reader.read(pageIndex, param);
                        } else {
                            imageData = reader.read(pageIndex, param);
                            //imageData = reader.readAsRenderedImage(pageIndex, param);
                            //TODO Reenable the above when proper listeners are implemented
                            //to react to late pixel population (so the stream can be closed
                            //properly).
                        }
                        if (iiometa == null) {
                            iiometa = reader.getImageMetadata(pageIndex);
                        }
                        providerIgnoresICC = checkProviderIgnoresICC(reader
                                .getOriginatingProvider());
                        break; //Quit early, we have the image
                    } catch (IndexOutOfBoundsException indexe) {
                        throw new ImageException("Page does not exist. Invalid image index: "
                                + pageIndex);
                    } catch (IllegalArgumentException iae) {
                        //Some codecs like com.sun.imageio.plugins.wbmp.WBMPImageReader throw
                        //IllegalArgumentExceptions when they have trouble parsing the image.
                        throw new ImageException("Error loading image using ImageIO codec", iae);
                    } catch (IIOException iioe) {
                        if (firstException == null) {
                            firstException = iioe;
                        } else {
                            log.debug("non-first error loading image: " + iioe.getMessage());
                        }
                    }
                    try {
                        //Try fallback for CMYK images
                        BufferedImage bi = getFallbackBufferedImage(reader, pageIndex, param);
                        imageData = bi;
                        firstException = null; //Clear exception after successful fallback attempt
                        break;
                    } catch (IIOException iioe) {
                        //ignore
                    }
                    imgStream.reset();
                } finally {
                    reader.dispose();
                }
            }
        } finally {
            ImageUtil.closeQuietly(src);
            //TODO Some codecs may do late reading.
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.