Package javax.imageio

Examples of javax.imageio.ImageReader


        return true;
      }
      File outputFile = new File(cinema.getExtDataFolder(),args[1]);
     
      Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("gif");
      ImageReader reader = readers.next();
      ImageInputStream iis=null;
      try {
        iis = ImageIO.createImageInputStream(inputFile);
      }catch (IOException e) {
        e.printStackTrace();
      }
      reader.setInput(iis);
      LinkedList<Frame> frames = new LinkedList<Frame>();
      for(int i =0;true;i++){
        try {
          BufferedImage bi = reader.read(i);
          frames.add(new Frame(bi,alignment));
        } catch (IndexOutOfBoundsException e){
          break;
        } catch (IOException e) {
          e.printStackTrace();
View Full Code Here


          
            try {
                Iterator<ImageReader> iterator =
                    ImageIO.getImageReadersByMIMEType(type);
                if (iterator.hasNext()) {
                    ImageReader reader = iterator.next();
                    try {
                        ImageInputStream imageStream = ImageIO.createImageInputStream(
                                new CloseShieldInputStream(stream));
                        try {
                            reader.setInput(imageStream);
                           
                            metadata.set(Metadata.IMAGE_WIDTH, Integer.toString(reader.getWidth(0)));
                            metadata.set(Metadata.IMAGE_LENGTH, Integer.toString(reader.getHeight(0)));
                            metadata.set("height", Integer.toString(reader.getHeight(0)));
                            metadata.set("width", Integer.toString(reader.getWidth(0)));

                            loadMetadata(reader.getImageMetadata(0), metadata);
                        } finally {
                            imageStream.close();
                        }
                    } finally {
                        reader.dispose();
                    }
                }
               
                // Translate certain Metadata tags from the ImageIO
                //  specific namespace into the general Tika one
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

              break;
          default:
              throw new
                  IOException("Unexpected compression type: " + type);
        }
        ImageReader reader =
            ImageIO.getImageReadersByFormatName(format).next();
        if (reader == null) {
            throw new RuntimeException(I18N.getString("BMPImageReader4") +
                                       " " + format);
        }
        // prepare input
        byte[] buff = new byte[(int)imageSize];
        iis.read(buff);
        reader.setInput(ImageIO.createImageInputStream(new ByteArrayInputStream(buff)));
        if (bi == null) {
            ImageTypeSpecifier embType = reader.getImageTypes(0).next();
            bi = embType.createBufferedImage(destinationRegion.x +
                                             destinationRegion.width,
                                             destinationRegion.y +
                                             destinationRegion.height);
        }

        reader.addIIOReadProgressListener(new EmbeddedProgressAdapter() {
                public void imageProgress(ImageReader source,
                                          float percentageDone)
                {           
                    processImageProgress(percentageDone);
                }
            });

        reader.addIIOReadUpdateListener(new IIOReadUpdateListener() {
                public void imageUpdate(ImageReader source,
                                        BufferedImage theImage,
                                        int minX, int minY,
                                        int width, int height,
                                        int periodX, int periodY,
                                        int[] bands)
                {
                    processImageUpdate(theImage, minX, minY,
                                       width, height,
                                       periodX, periodY, bands);
                }
                public void passComplete(ImageReader source,
                                         BufferedImage theImage)
                {
                    processPassComplete(theImage);
                }
                public void passStarted(ImageReader source,
                                        BufferedImage theImage,
                                        int pass,
                                        int minPass, int maxPass,
                                        int minX, int minY,
                                        int periodX, int periodY,
                                        int[] bands)
                {
                    processPassStarted(theImage, pass, minPass, maxPass,
                                       minX, minY, periodX, periodY,
                                       bands);
                }
                public void thumbnailPassComplete(ImageReader source,
                                                  BufferedImage thumb) {}
                public void thumbnailPassStarted(ImageReader source,
                                                 BufferedImage thumb,
                                                 int pass,
                                                 int minPass, int maxPass,
                                                 int minX, int minY,
                                                 int periodX, int periodY,
                                                 int[] bands) {}
                public void thumbnailUpdate(ImageReader source,
                                            BufferedImage theThumbnail,
                                            int minX, int minY,
                                            int width, int height,
                                            int periodX, int periodY,
                                            int[] bands) {}
            });

        reader.addIIOReadWarningListener(new IIOReadWarningListener() {
                public void warningOccurred(ImageReader source, String warning)
                {
                    processWarningOccurred(warning);
                }
            });
        ImageReadParam param = reader.getDefaultReadParam();
        param.setDestination(bi);
        param.setDestinationBands(bmpParam.getDestinationBands());
        param.setDestinationOffset(bmpParam.getDestinationOffset());
        param.setSourceBands(bmpParam.getSourceBands());
        param.setSourceRegion(bmpParam.getSourceRegion());
        param.setSourceSubsampling(bmpParam.getSourceXSubsampling(),
                                   bmpParam.getSourceYSubsampling(),
                                   bmpParam.getSubsamplingXOffset(),
                                   bmpParam.getSubsamplingYOffset());
        reader.read(0, param);
        return bi;
    }
View Full Code Here

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

            //we can calculate the preferred size only for JPEG and PNG
            //other formats like WMF, EMF and PICT are not supported in Java
            case HSSFWorkbook.PICTURE_TYPE_JPEG:
            case HSSFWorkbook.PICTURE_TYPE_PNG:
                BufferedImage img = null;
                ImageReader r = null;
                try {
                    //read the image using javax.imageio.*
                    ImageInputStream iis = ImageIO.createImageInputStream( new ByteArrayInputStream(data) );
                    Iterator i = ImageIO.getImageReaders( iis );
                    r = (ImageReader) i.next();
                    r.setInput( iis );
                    img = r.read(0);

                    int[] dpi = getResolution(r);
                    int imgWidth = img.getWidth()*96/dpi[0];
                    int imgHeight = img.getHeight()*96/dpi[1];

 
View Full Code Here

  public BufferedImage read(Class<? extends BufferedImage> clazz, HttpInputMessage inputMessage)
      throws IOException, HttpMessageNotReadableException {

    ImageInputStream imageInputStream = null;
    ImageReader imageReader = null;
    try {
      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) {
        try {
          imageInputStream.close();
        }
View Full Code Here

    try {
      final ImageInputStream imis =
        ImageIO.createImageInputStream(new ByteArrayInputStream(data));
      final Iterator it = ImageIO.getImageReaders(imis);
      if (it.hasNext()) {
        final ImageReader rd = (ImageReader)it.next();
        format = rd.getFormatName().toLowerCase();
      }
    } catch (IOException ex) {
      //not possible, but eat it and recover it later
    }
View Full Code Here

      public Object readFrom(InputStream in) {
         Object converted = null;
        
         try
         {
            ImageReader decoder = ImageIO.getImageReadersByFormatName("JPEG").next();
            ImageInputStream iis = ImageIO.createImageInputStream(in);
            decoder.setInput(iis);
            BufferedImage bim = decoder.read(0);
            converted = bim;
         }
         catch (Exception e)
         {
            e.printStackTrace();
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.