ryyst
ryyst

Reputation: 9791

Java - process image while reading it

I'm designing a server-side application that takes an image from a user, processes it, and sends it back over the network. Since the network connection might be quite slow, I'd like to speed things up by starting to process parts of the image while it is still being sent over the network and send parts of the processed image back to the client while other parts are still being processed.

Is this possible, preferably using the javax.imageio classes?

EDIT: I am mostly interested in writing PNGfiles. Wikipedia says: "IDAT contains the image, which may be split among multiple IDAT chunks. Doing so increases filesize slightly, but makes it possible to generate a PNG in a streaming manner."

Upvotes: 1

Views: 312

Answers (1)

This strongly depends on the encoding of the image. Some image formats require the whole file to be available before you can decode it. Others - like GIF and some PNG encodings (as far as I remember) decode to indvidual blocks which can then be processed.

You most likely need to write custom decoders, which may be quite a bit of work if you are not intimately familiar with the formats, and you need to support several.

I think you perhaps should work on an upload bar instead?

Upvotes: 2

Related Questions