Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to read bitmap and meta-data from a png stream/file efficiently?
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload