Skip to content

PNGj: Row writing order

The purpose is to draw a small image inside another image at some specified area. Is there any possibility to change only specified rows and avoid rewriting of entire lines of the origin image? I tried to write only the subimage rows and result was predictable: rows must be written in order: expected:0 passed:1781


The PNG format uses zlib compression. The compressed representation of each row depends upon the preceding compressed data, and because of PNG filtering, also can depend upon the previous row. So you must read the entire image, change the rows that you want to change, and then rewrite the entire image.

Theoretically it’s possible to write a PNG that could be edited, by flushing and restarting the compressor at the beginning of each row, but the compression ratio would suffer as a result. I don’t know of any applications that actually do that. You’d also have to limit the PNG filtering to just the NONE and SUB filters, which don’t need access to the previous row.

Best to just go ahead and rewrite the entire image.