为什么从缓存加载图像时图像方向会发生变化?

时间:2013-01-23 13:29:51

标签: iphone ios ipad

我有一个应用程序,我从图像缓存加载图像。

if(![[ImageCache sharedImageCache] hasImageWithKey:imagepath])

                {   cell.bannerview2.image = [UIImage imageNamed:@"no_imags.png"];
                    NSArray *myArray = [NSArray arrayWithObjects:cell.bannerview2,imagepath,@"no_imags.png",[NSNumber numberWithBool:NO],nil];
                    AppDelegate *appDelegate = (AppDelegate  *)[[UIApplication sharedApplication] delegate];
                    [appDelegate performSelectorInBackground:@selector(updateImageViewInBackground:) withObject:myArray];   

                }
                else 
                {
                    cell.bannerview2.image = [[ImageCache sharedImageCache] getImagefromCacheOrUrl:imagepath];
                 }
            }
            else
            {
                cell.bannerview2.image = [UIImage imageNamed:@"no_imags.png"];  

            } 

这就是我在进行图像缓存过程的方法。但问题是当图像大于所需的帧时图像方向正在改变。这是我在appdelegate中的图像更新代码

-(void)updateImageViewInBackground:(NSArray *)idsArray{
    //NSLog(@"IN METHOD idsArray %@",idsArray);
    NSString *iconurl = (NSString *)[idsArray objectAtIndex:1];

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    if([[ImageCache sharedImageCache] hasImageWithKey:iconurl]){
        [self performSelectorOnMainThread:@selector(updateImageViewInForeground:) withObject:idsArray waitUntilDone:NO];
        [pool release];
        return;
    }
    if([iconurl length] > 0){
        [[ImageCache sharedImageCache] saveImageToCacheOfUrl:iconurl];
    }
    [self performSelectorOnMainThread:@selector(updateImageViewInForeground:) withObject:idsArray waitUntilDone:NO];
    [pool release];
}
-(void)updateImageViewInForeground:(NSArray *)idsArray{

    UIImageView *weatherView = (UIImageView *)[idsArray objectAtIndex:0];
    NSString *iconurl = (NSString *)[idsArray objectAtIndex:1];
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    weatherView.image = [[ImageCache sharedImageCache] getImagefromCacheOrUrl:iconurl];
    if(weatherView.image == nil){
        NSString *defaultname = (NSString *)[idsArray objectAtIndex:2];
        weatherView.image = [UIImage imageNamed: defaultname];
    }
    BOOL resizeImgView = [(NSNumber *)[idsArray objectAtIndex:3] boolValue];
    if(resizeImgView){
        //NSLog(@"resizeImgView %@ %@",iconurl,weatherView);
        weatherView.frame = CGRectMake(weatherView.frame.origin.x, weatherView.frame.origin.y, weatherView.image.size.width, weatherView.image.size.height);





    }
    [pool release];
}

任何人都可以帮助我吗?

0 个答案:

没有答案