iPhone - 通过HTTP接收的图像的JPEG数据损坏 [英] iPhone - Corrupt JPEG data for image received over HTTP

查看:121
本文介绍了iPhone - 通过HTTP接收的图像的JPEG数据损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过HTTP获取图像,使用NSURLConnection,如下 -

I'm getting an image over HTTP, using NSURLConnection, as follows -

NSMutableData *receivedData;

- (void)getImage {
    self.receivedData = [[NSMutableData alloc] init];
    NSURLConnection *theConnection = // create connection
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {    
   [receivedData appendData:data];
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
   [connection release];

   UIImage *theImage = [UIImage imageWithData:receivedData];
}

通常它工作正常,但有时我看到这个记录 - :损坏的JPEG数据:数据段过早结束

Usually it works just fine, but sometimes I'm seeing this get logged - : Corrupt JPEG data: premature end of data segment

此时,图像无法完全呈现。我可能会看到它的75%,然后右下角是一个灰色框。

At this point, the image does not completely render. I'll see maybe 75% of it, and then the lower right hand corner is a grey box.

有关如何解决这个问题的任何想法?

Any ideas on how to approach fixing this? Am I constructing my image improperly?

推荐答案

您的HTTP代码看起来是否正确。您可能希望在完成加载后记录receiveData的大小,并将其与服务器上预期的映像大小进行比较。如果是预期的大小,则可能是服务器上的图片本身已损坏。

Your HTTP code looks correct. You might want to log the size of the receivedData once it's done loading and compare it to the expected size of the image on the server. If it's the expected size, then maybe the image itself is corrupted on the server.

这篇关于iPhone - 通过HTTP接收的图像的JPEG数据损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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