Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I start showing an interlaced PNG before all data has been received?

I have a slow connection that I need to send a PNG image over (as a byte stream) and have the image be displayed immediately. I have a C# WinForms app accepting the byte[], loading it into a memory stream, and creating an System.Drawing.Image/Bitmap object from it.

What I would like to do is send a super low resolution image down, and then incrementally update it so that it gets clearer as the data is received. It looks like PNG supports interlaced images which do just what I want.

Is it possible to start showing the PNG before all the data is received and incrementally make it clearer as the rest of it comes in? How can I do this?

like image 229
NotDan Avatar asked Oct 29 '09 17:10

NotDan


People also ask

Should you interlace a PNG?

The interlaced option is pretty much obsolete today. It is to let someone with a slow internet connection like Dial-Up begin to see the picture quickly. An interlaced PNG displays an early degraded version of the whole image quickly, then displays the image correctly. Interlaced will be a bit bigger in filesize.

What does interlaced mean when saving a PNG?

Interlaced image loads an early degraded version of the whole image as soon as possible and then progressively renders the image to clear state. Non-interlaced image will load up in tiles showing clear image in each tile as it progresses to load in the image.

Does JPEG support interlacing?

Lots of image formats support interlacing, including GIF, JPEG, and PNG. Those three all do it differently. A bit of a terminology snafu here: JPEG calls its interlaced images "progressive JPEGs", which is a little bit confusing because in the video world, "progressive" explicitly means "non-interlaced".


1 Answers

You'd have to deliver the bytes in such a way that they conform to the Adam7 algorithm. Possibly a 3rd-party library could be Googled that delivers the bytes in such a way to take the hard work out of it.

Here's a visual example of what it would do.

Edit: LibPNG for Windows might be a start. Of course its DLL would require your .NET program to interact with unmanaged code and non-MSIL assemblies, and that's another story that I'm sure is posted elsewhere on stackoverflow - or maybe you could create another question for it in particular. LibPNG is an open source project so looking at its source code might provide insight on the Adam7 algorithm that could be recoded in C#/.NET.

like image 131
John K Avatar answered Nov 07 '22 14:11

John K