title: how to read bitmap and meta-data from a png stream/file efficiently?
body: <p>I need to decode both bitmap and meta data from PNG input stream using [PNGJ] (http://code.google.com/p/pngj/) library. The problem is that decoding meta data will advance the stream and then I cannot use 
  bitmap = BitmapFactory.decodeStream().</p>
  
  <p>Creating Bitmap on my own is OK but if I need to, say, scale bitmap with interpolation I'd rather  use BitmapFactory. To use it I have to create a copy of InputStream every time I have to use PNGJ for getting meta data and BitmapFactory for getting a bitmap. It will be nice to return meta data AND Bitmap from a single PNGJ call (at least for most common ARGB_8888 format). </p>
  
  <p>In a nutshell, I have to copy the stream to be used by Java libraries which looks like a waste. Returning a bitmap will be one solution.</p>
  
  <pre><code>    // register an auxilary chunk name 
      PngChunk.factoryRegister(ThumbNailProvider.chunkID, chunkPROP.class); 
  
      // reader for the stream
      PngReader pngr = new PngReader(inStream, "debug label PNG reader");
      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      PngWriter pngw = new PngWriter(outputStream, pngr.imgInfo);
  
      // copy pre-data chunks
      pngw.copyChunksFirst(pngr, ChunkCopyBehaviour.COPY_ALL_SAFE);
  
      // copy image data
      for (int row = 0; row &lt; pngr.imgInfo.rows; row++) {
          ImageLine l1 = pngr.readRow(row);
          pngw.writeRow(l1, row);
      }
  
      // copy after-data chunks
      pngw.copyChunksLast(pngr, ChunkCopyBehaviour.COPY_ALL); 
  
      pngr.end(); // close inStream but not its copy
      pngw.end(); // close out stream
  
      // save a copy of the stream for Java Libraries;
      data.inputStream = new ByteArrayInputStream(outputStream.toByteArray());
  
  
  
      // read the chunk
      ChunksList chunkList = pngr.getChunksList();
      PngChunk chunk = chunkList.getById1(L2ThumbNailProvider.chunkID);
      if (chunk != null) {
      ... 
      }
  </code></pre>