在UIImageView中显示隔行扫描(逐行扫描)图像 [英] Displaying interlaced (progressive) Image in UIImageView

查看:124
本文介绍了在UIImageView中显示隔行扫描(逐行扫描)图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在下载时显示JPEG图像,使用部分数据,类似于许多网络浏览器或facebook应用程序。

I am trying to display a JPEG image as it downloads, using part of the data, similiar to many web browsers do, or the facebook app.

图像的低质量版本(只是数据的一部分),然后以完整质量显示完整图像。

there is a low-quality version of the image(just part of the data) and then display the full image in full quality.

这最好显示在视频在这里

我遵循了这个问题:

如何在下载时在UIImageView中显示渐进式JPEG?

但我得到的只是一个imageview,当数据保持进入时呈现,没有低质量版本,没有真正的渐进式下载和渲染。

but all I got was a imageview that is being rendered as data keeps comes in, no low-quality version first, no true progressive download and render.

任何人都可以共享一个代码段或指向我可以找到更多信息,如何这可能是imp在iOS应用程序中发布了吗?

can anyone share a code snippet or point me to where I can find more info as to how this can be implemented in an iOS app ?

尝试此链接,例如显示JPEG信息,它将图像标识为渐进式

tried this link for example which shows JPEG info, it identifies the image as progressive

http://www.webpagetest.org/jpeginfo/jpeginfo.php?url=http://cetus.sakura.ne.jp/softlab/software/spibench/pic_22p.jpg

我使用了正确的代码序列

and I used the correct code sequence

-(void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data
{
    /// Append the data
    [_dataTemp appendData:data];

    /// Get the total bytes downloaded
    const NSUInteger totalSize = [_dataTemp length];
    /// Update the data source, we must pass ALL the data, not just the new bytes
    CGImageSourceUpdateData(_imageSource, (CFDataRef)_dataTemp, (totalSize == _expectedSize) ? true : false);

    /// We know the expected size of the image
    if (_fullHeight > 0 && _fullWidth > 0)
    {
            [_imageView setImage:[UIImage imageWithCGImage:image]];
            CGImageRelease(image);
    }
}

但代码仅在完成后显示图像加载,与其他图像一样,它会在下载时显示,但只从上到下,没有低质量的版本,然后逐步添加细节,如浏览器。

but the code only shows the image when it is finished loading, with other images, it will show it as it downloading, but only top to bottom, no low quality version and then progressively add detail as browsers do.

DEMO PROJECT HERE

推荐答案

这是我有一段时间感兴趣的主题:似乎没有办法用Apple的API做你想做的事,但如果你能投入时间,你可以可能会让它工作。

This is a topic I've had some interest in for a while: there appears to be no way to do what you want using Apple's APIs, but if you can invest time in this you can probably make it work.

首先,你需要一个JPEG解码库:libjpeg或的libjpeg涡轮。然后,您需要将其集成到可以与Objective-C一起使用的内容中。有一个开源项目使用这个库, PhotoScrollerNetwork ,利用turbo库来动态解码非常大的jpegs 当他们下载时,他们可以进行平移和缩放(PhotoScroller是一个Apple项目,可以进行平移和缩放,但需要预先平铺的图像)。

First, you are going to need a JPEG decoding library: libjpeg or libjpeg-turbo. You will then need to integrate it into something you can use with Objective-C. There is an open source project that uses this library, PhotoScrollerNetwork, that uses leverages the turbo library to decode very large jpegs "on the fly" as they download, so they can be panned and zoomed (PhotoScroller is an Apple project that does the panning and zooming, but it requires pre-tiled images).

上面的项目并不是你想要的,你应该能够解除大部分的libjpeg-turbo界面来解码渐进式图像,并在收到它们时返回低质量的图像。看起来您的图像非常大,否则几乎不需要渐进式图像,因此您也可以找到上述使用项目的平移/缩放功能。

While the above project is not exactly what you want, you should be able to lift much of the libjpeg-turbo interface to decode progressive images and return the low quality images as they are received. It would appear that your images are quite large, otherwise there would be little need for progressive images, so you may find the panning/zooming capability of the above project of use as well.

PhotoScrollerNetwork的一些用户已请求支持渐进式图像,但似乎在网络上几乎没有使用它们。

Some users of PhotoScrollerNetwork have requested support for progressive images, but it seems there is very little general use of them on the web.

编辑:第二个想法:如果它是你的网站,你将用它来出售渐进式图像(我认为这是因为通常很少找到),你可以采取完全不同的机智。

A second idea: if it's your site that you would use to vend progressive images (and I assume this since there are so few to be found normally), you could take a completely different tact.

在这种情况下,您将构建一个您自己设计的二进制文件 - 其中包含4个图像。前四个字节将提供其后的数据长度(并且每个后续图像将使用相同的4字节前缀)。然后,在iOS端,当下载开始时,一旦你获得了第一个图像的完整字节,就可以使用它们构建一个小的低分辨率UIImage,并在接收下一个图像时显示它。当下一个完全到达时,您将使用较新的较高分辨率图像更新低分辨率图像。它可能你可以使用拉链容器和飞行减压 - 不是100%肯定。在任何情况下,以上都是您问题的标准解决方案,并且会为libjpeg提供几乎相同的性能,而且工作量要少得多。

In this case, you would construct a binary file of your own design - one that had say 4 images inside it. The first four bytes would provide the length of the data following it (and each subsequent image would use the same 4-byte prefix). Then, on the iOS side, as the download starts, once you got the full bytes of the first image, you could use those to build a small low res UIImage, and show it while the next image was being received. When the next one fully arrives, you would update the low res image with the newer higher res image. Its possible you could use a zip container and do on the fly decompression - not 100% sure. In any case, the above is a standard solution to your problem, and would provide near-identical performance to libjpeg, with much much less work.

这篇关于在UIImageView中显示隔行扫描(逐行扫描)图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆