Android: How to render a streaming image on the fly in ImageView without loading a full bitmap?

I am loading an image from the URL that will be displayed in ImageView. The standard way is to create a bitmap as follows (where InputStream is obtained from the URL):

 Bitmap bm = BitmapFactory.decodeStream(is); 

But I'm dealing with large images, and I want to start displaying pixels before the entire image is loaded into a bitmap, that is, I want to achieve progressive image rendering (similar to loading large images in web browsers). If the image is, for example, interlaced PNG, this will allow me to show users of lower quality while they wait for the entire image to load. Basically, I want to achieve rendering, as shown in http://www.codinghorror.com/blog/2005/12/progressive-image-rendering.html

I know if I can implement a PNG decoder or use an open source implementation, I could change it to display pixels in an ImageView bitmap as soon as I read them, but it looks like a giant effort for what I intend .

+6
source share
2 answers

Simple progressive rendering . This is achieved by considering the network transmission layer (TCP). Each packet received in order is delivered at the application level, which is displayed immediately. If you want to achieve this, you need to think about programming sockets in your application.

However, this is an old approach and actually a more intensive computing process. I personally prefer working with a stub. The stub image is displayed at the beginning, and an immediate flow begins with the url connecting and loading (manager or cache). Once the download is complete, you will be returned to your main stream to update the photo. It is more convenient.

Please correct me if I am mistaken in any sense.

0
source

Try the Facebook Freso project: http://frescolib.org/#streaming I'm not sure which file formats it supports, but it supports progressive rendering of JPEGs that have been encoded gradually.

0
source

Source: https://habr.com/ru/post/947635/


All Articles