I am loading an image from a URL to be shown in an ImageView. The standard way is to create a bitmap as follows (where the InputStream is
has been obtained from the URL):
我正在从URL加载图像以显示在ImageView中。标准方法是按如下方式创建位图(其中InputStream是从URL获取的):
Bitmap bm = BitmapFactory.decodeStream(is);
But I am dealing with large images, and I want to start displaying pixels before the entire image is loaded in the bitmap i.e. I want achieve progressive rendering of the image (similar to loading of large images in web browsers). If the image is, for instance, an interlaced PNG, this will allow me to show a lower quality image to users while they wait for the full image to load. Basically, I want to achieve rendering as shown in http://www.codinghorror.com/blog/2005/12/progressive-image-rendering.html
但我正在处理大图像,我想在整个图像加载到位图之前开始显示像素,即我希望实现图像的渐进式渲染(类似于在Web浏览器中加载大图像)。例如,如果图像是隔行扫描的PNG,这将允许我在等待加载完整图像时向用户显示较低质量的图像。基本上,我想实现渲染,如http://www.codinghorror.com/blog/2005/12/progressive-image-rendering.html所示
I know if I could implement a PNG decoder, or use an opensource implementation, I could modify it to render pixels to the ImageView's bitmap as soon as I read them, but that looks like a mammoth effort for what I intend.
我知道如果我可以实现一个PNG解码器,或者使用一个开源实现,我可以修改它,一旦我读取它就将像素渲染到ImageView的位图,但这看起来像是我想要的巨大努力。
2 个解决方案
#1
0
Simple progressive as-received rendering: This is achieved by considering transmission network layer (TCP). Every packet received in order, is delivered in the application layer which is displayed immediately. If you wish to achieve this, then you need to think about socket programming in you application.
简单的渐进式接收渲染:这是通过考虑传输网络层(TCP)来实现的。按顺序接收的每个数据包都会立即显示在应用程序层中。如果您希望实现这一点,那么您需要考虑应用程序中的套接字编程。
However, this is an old approach and actually more computation intensive one. I personally prefer, working out with a stub image. The stub image is shown at the start, and an immediate thread with a url connection and download (manager or cache) is started. Once the download is completed, you get back to your main thread to update the photo. This is more organizable.
然而,这是一种旧方法,实际上是计算密集型方法。我个人更喜欢,使用存根图像。存根图像显示在开头,并启动具有URL连接和下载(管理器或缓存)的立即线程。下载完成后,您将返回主线程以更新照片。这更具组织性。
Please correct me if I'm wrong in any sense.
如果我在任何意义上都错了,请纠正我。
#2
0
Try Facebook's Freso project: http://frescolib.org/#streaming I'm not sure what file formats it supports, but it supports progressive rendering of JPEGs that have been encoded progressively.
试试Facebook的Freso项目:http://frescolib.org/#streaming我不确定它支持哪种文件格式,但它支持逐步编码的JPEG渐进式渲染。
#1
0
Simple progressive as-received rendering: This is achieved by considering transmission network layer (TCP). Every packet received in order, is delivered in the application layer which is displayed immediately. If you wish to achieve this, then you need to think about socket programming in you application.
简单的渐进式接收渲染:这是通过考虑传输网络层(TCP)来实现的。按顺序接收的每个数据包都会立即显示在应用程序层中。如果您希望实现这一点,那么您需要考虑应用程序中的套接字编程。
However, this is an old approach and actually more computation intensive one. I personally prefer, working out with a stub image. The stub image is shown at the start, and an immediate thread with a url connection and download (manager or cache) is started. Once the download is completed, you get back to your main thread to update the photo. This is more organizable.
然而,这是一种旧方法,实际上是计算密集型方法。我个人更喜欢,使用存根图像。存根图像显示在开头,并启动具有URL连接和下载(管理器或缓存)的立即线程。下载完成后,您将返回主线程以更新照片。这更具组织性。
Please correct me if I'm wrong in any sense.
如果我在任何意义上都错了,请纠正我。
#2
0
Try Facebook's Freso project: http://frescolib.org/#streaming I'm not sure what file formats it supports, but it supports progressive rendering of JPEGs that have been encoded progressively.
试试Facebook的Freso项目:http://frescolib.org/#streaming我不确定它支持哪种文件格式,但它支持逐步编码的JPEG渐进式渲染。