Package net.charabia.util.io

Examples of net.charabia.util.io.BinaryInputStream


    static public BufferedImage[] loadImages(File f) throws IOException
    {
  InputStream istream = new FileInputStream(f);
        BufferedInputStream buffin = new BufferedInputStream(istream);
  BinaryInputStream in = new BinaryInputStream(buffin);

  try {
      in.mark(1024 * 1024);

      IconDir dir = new IconDir(in);
      //      System.out.println("DIR = " + dir);

      IconEntry[] entries = new IconEntry[dir.idCount];
      BufferedImage[] images = new BufferedImage[dir.idCount];

      for (int i=0; i<dir.idCount; i++)
    {
        entries[i] = new IconEntry(in);
        //        System.out.println("ENTRY " + i + " = " + entries[i]);
    }

      IconEntry entry = entries[0];
      //      System.out.println("ENTRYx = " + entry);

      for (int i=0; i<dir.idCount; i++)
    {
        in.reset();

        boolean pngIcon = false;
        if (entries[i].dwBytesInRes > PNG_SIGNATURE.length) {
          //     Check if this is a PNG icon (introduced in Windows Vista)
          in.mark(1024 * 1024);
          in.skip(entries[i].dwImageOffset);
          byte[] signatureBuffer = new byte[PNG_SIGNATURE.length];
          in.read(signatureBuffer, 0, PNG_SIGNATURE.length);
          pngIcon = Arrays.equals(PNG_SIGNATURE, signatureBuffer);
          in.reset();
        }
        //    System.out.println("PNG Icon = " + pngIcon);

        in.skip(entries[i].dwImageOffset);

        BufferedImage image;

        if (pngIcon) {
          // This is a PNG icon (introduced in Windows Vista)
          byte[] imageData = new byte[(int) entries[i].dwBytesInRes];
          in.read(imageData, 0, (int) entries[i].dwBytesInRes);
          ByteArrayInputStream imageDataBuffer = new ByteArrayInputStream(imageData);
          image = ImageIO.read(imageDataBuffer);
        } else {
          //    This is a standard icon (not PNG)
          IconHeader header = new IconHeader(in);
          //        System.out.println("Header: " + header);

          long toskip = header.Size - 40;
          if (toskip>0)
        in.skip((int)toskip);

          //    System.out.println("skipped data");


          switch(header.BitsPerPixel)
View Full Code Here

TOP

Related Classes of net.charabia.util.io.BinaryInputStream

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.