0

json からの画像ロードでUIImage描画したいものがあります。UILabel

描画する前に画像を保存したい。

画像をロードしましたが、描画しません。画像の問題を保存したと思います。

これが私のコードです:

- (void)createDirectory {

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    itemsFilename = [[NSString alloc] initWithString:[documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"listEPG"]]];
    thumbsFilename = [[NSString alloc] initWithString:[documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"listImage"]]];
    _itemsNames = [[NSMutableArray alloc] initWithContentsOfFile:itemsFilename];
    images = [[NSMutableDictionary alloc] initWithContentsOfFile:thumbsFilename];
    imagesOperations = [[NSOperationQueue alloc] init];
    [imagesOperations setMaxConcurrentOperationCount:1];

    if (images == nil) {
        images = [[NSMutableDictionary alloc] init];
    }
}


- (void)drawRect:(CGRect)rect {

    for(int i = 0;i<10;i++) {
        NSString* imageUrl= [NSString stringWithFormat:@"%@",[[[data objectAtIndex:i] objectForKey:@"Channel"] objectForKey:@"Image"]];

        UIImage *imgLogo = [self setImage:imageUrl];
        NSLog(@"%@",imgLogo);
        [imgLogo drawInRect:CGRectMake(0,y_lblLogo,70.f,30.f)];
    }
}

- (UIImage *) setImage:(NSString *)theUrl {
    //NSLog(@"%@",theUrl);
    id userImage = [images objectForKey:theUrl];

    if(userImage == nil) {
        [images setObject:[NSNull null] forKey:theUrl];
        GetImage *op = [[GetImage alloc] initWithTheURL:theUrl target:self action:@selector(getImage:)];
        NSLog(@"%@",op);        //[imagesOperations addOperation:op];
    } else if ([userImage isKindOfClass:[NSData class]]) {
        return [UIImage imageWithData:userImage];
    }
    return [UIImage imageNamed:@""];
}

- (void) getImage:(NSDictionary *)info {

    NSString* url = [info objectForKey:@"url"];
    id image = [info objectForKey:@"image"];
    [images setObject:UIImageJPEGRepresentation(image, 0.5) forKey:url];
    [images writeToFile:thumbsFilename atomically:YES];
    NSMutableSet *filepathsSet = [[NSUserDefaults standardUserDefaults] objectForKey:@"filePathLogoChannel"];
    [filepathsSet setByAddingObject:thumbsFilename];
    [[NSUserDefaults standardUserDefaults] setObject:filepathsSet forKey:@"filePathLogoChannel"];
}
4

1 に答える 1

0

変化する

id image = [info objectForKey:@"image"];
[images setObject:UIImageJPEGRepresentation(image, 0.5) forKey:url];
[images writeToFile:thumbsFilename atomically:YES];

UIImage *image = (UIImage *)[info objectForKey:@"image"];
NSData *imageData = UIImageJPEGRepresentation(image, 0.5);
[imageData writeToFile:thumbsFilename atomically:YES];  
于 2012-10-28T09:04:08.467 に答える