简体   繁体   English

iOS图像分辨率问题

[英]iOS image resolution issue

In My project I am using image view which downloads image from server. 在我的项目中,我使用的是从服务器下载图像的图像视图。 It is working fine on iOS 4 but it is not showing on iOS 5. 在iOS 4上运行正常,但在iOS 5上未显示。

Is there any minimum resolution needs to be take care while using iOS 5. One of image which comes from server is of 72 dpi resolution which works on iOS 4 but not on iOS 5. 使用iOS 5时是否需要注意任何最低分辨率要求。来自服务器的图像之一为72 dpi分辨率,该分辨率在iOS 4上有效,但在iOS 5上无效。

I have written category to image view which will download code from image URL Here is code snippet: 我已将类别写到图像视图,它将从图像URL下载代码。这是代码片段:

- (void) setImageFromServer:(NSString *) imageURL 
{
    if (imageURL!=nil) 
    {
        ImageDownloader *imageDownloader = [[[ImageDownloader alloc] init] autorelease];
        imageDownloader.requester = self;
        [imageDownloader startDownload:imageURL]; 
    }
}


- (void) didDownloadImageData:(NSData *) data forImageURL:(NSString *) imageURL 
{
    [self setImage:[UIImage imageWithData:data]];
}

In downloader file : 在下载文件中:

- (void) startDownload:(NSString *)MyimageURL {

    self.imageData = [NSMutableData data];
    self.currentImageURL = MyimageURL;

    self.downloadConnection = [NSURLConnection connectionWithRequest: [NSURLRequest requestWithURL:[NSURL URLWithString:self.currentImageURL]]
                                                            delegate: self];
    [self.downloadConnection start];
}



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

- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
    [self.requester didDownloadImageData:self.imageData forImageURL:self.currentImageURL];
    isRewardTagImageAvailable = YES;
    [connection release];
    connection = nil;
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{

}

I am not sure if this is a problem, but usually when I am writing a NSURLRequest I first initialize things as follows and the insert the request into a NSURLConnection. 我不确定这是否有问题,但是通常在编写NSURLRequest时,我首先按如下所示初始化事物,然后将请求插入NSURLConnection。 Sort of like this. 有点像这样。 Also note that once you initWithRequst in a NSURLConnection, you do not have to tell that connection to start, it will automatically. 还要注意,一旦您在NSURLConnection中使用initWithRequst,就不必告诉该连接开始,它将自动进行。

NSURLRequest *tempReq = [[NSURLRequest alloc] initWithURL:someURL cachePolicy:NSURLRequestReloadIgnoringCacheData  timeoutInterval:10.0];
NSURLConnection *tempCon = [[NSURLConnection alloc] initWithRequest:tempReq delegate:self];

I mean it should not matter, but give that a shot because looking at your, code it looks fine. 我的意思是没关系,但是试一下,因为看着您的代码看起来还不错。

I would recommend adding the didFailWithError method: 我建议添加didFailWithError方法:

-(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error;

To your files as well because maybe your connection is failing for some reason as well. 也要对文件进行处理,因为连接也可能由于某种原因而失败。

Is your connection synchronous or async ? 您的连接是同步还是异步?

If async, you shouldn't autorelease your ImageDownloader, because there are some chance that it would be released for the connectionDidFinishLoading message. 如果是异步的,则不应自动释放ImageDownloader,因为很有可能会为connectionDidFinishLoading消息释放它。

Try to alloc your ImageDownloader normally, then release it when it finishes the download (both in connectionDidFinishLoading and didFailWithError ) 尝试正常分配您的ImageDownloader,然后在完成下载后释放它(在connectionDidFinishLoadingdidFailWithError中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM