下载时如何在 UIImageView 中显示渐进式 JPEG?
从网上下载图像并将其显示在 UIImageView 中相当容易。然而,这需要在向用户显示图像之前完全下载图像,从而完全击败渐进式 JPEG(和 PNG)图像。
如何在传输完成时渲染部分下载的图像?我想象 SDK 有一些回调函数可以更新图像,但我找不到这样的函数。目前的 iOS SDK 是否可以实现?
Downloading an image from the net and showing it in an UIImageView is fairly easy. However, this requires the image to be completely downloaded before it is shown to the user, completely defeating progressive JPEG (and PNG) images.
How can I render the partially downloaded images while the transfer is being done? I would imagine the SDK to have some callback function which would update the image, but I can't find such a function. Is it possible at all with the current iOS SDK?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道这篇文章大约有 1 年的时间,但为了以防万一有人在寻找它,有一个名为 NYXImagesKit< /a> 这就是你正在寻找的。
它有一个名为
NYXProgressiveImageView
的类,它是UIImageView
的子类。您所要做的就是:
此外,一个不错的选择是将图像保存为隔行扫描图像,以便以低质量加载并随着下载而改进。如果图像不是隔行扫描,则会从上到下加载。
I know this post has about 1 year, but just in case anyone is looking for it, there is a project called NYXImagesKit that does what you are looking for.
It has a class named
NYXProgressiveImageView
that is a subclass ofUIImageView
.All you have to do is:
Also, a good option is to save your images as
interlaced
so that it loads with low quality and improve with the download. If the image is not interlaced it is loaded from top to bottom.现在在 libjpeg-turbo 之上有一个小型开源库,可以轻松解码和显示渐进式 JPEG:
请参阅 https://github.com/contentful-labs/Concorde
There is now a small open-source library on top of libjpeg-turbo which allows decoding and displaying progressive JPEGs easily:
see https://github.com/contentful-labs/Concorde
您是否尝试在 didReceiveData 被调用时部分渲染 UIImage ...?像……
Did you try to render the UIImage partially as didReceiveData gets called … ? Something like …