2011-01-19 58 views

回答

0

您是否嘗試渲染UIImage,因爲didReceiveData被調用...?喜歡的東西...

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
    //TODO: add some error handling in case the image could not be created 
    UIImage *img=[UIImage imageWithData:data]; 
    if (img) { 
     self.imageView.image=img; 
    } 
} 
+0

這不工作我想象的那麼糟糕所以我想現在會做。儘管如此,圖像顯示圖像尚未下載的區域的方式有點醜陋,並且由於完全重新計算圖像,在性能方面似乎比逐步解壓縮圖像更像原始libjpeg。 – 2011-01-27 10:28:15

+0

另一種方法(我猜更好的方法)是使用像libjpeg這樣的庫(如果適用於iOS)。 – versatilemind 2011-03-11 06:37:19

10

我知道這個帖子有1年左右,但以防萬一有人正在尋找它,有一個叫做NYXImagesKit項目已經做了你在找什麼。

它有一個名爲NYXProgressiveImageView的類,它是UIImageView的一個子類。

所有你需要做的是:

NYXProgressiveImageView * imgv = [[NYXProgressiveImageView alloc] init]; 
imgv.frame = CGRectMake(0, 0, 320, 480); 
[imgv loadImageAtURL:[NSURL URLWithString:@"http://yourimage"]]; 
[self.view addSubview:imgv]; 
[imgv release]; 

而且,一個很好的選擇是你的圖像保存爲interlaced以便它加載的低質量和下載改善。如果圖像不是交錯的,它會從上到下加載。

1

現在有許多關於libjpeg的渦輪增壓頂部的小型開放源碼庫,允許解碼和顯示輕鬆漸進式JPEG:

let imageView = CCBufferedImageView(frame: ...) 
if let url = NSURL(string: "http://example.com/yolo.jpg") { 
    imageView.load(url) 
} 

看到https://github.com/contentful-labs/Concorde