Я пытаюсь создать UIPickerView с некоторыми изображениями в нем, но я не могу понять, как сделать так, чтобы изображения соответствовали виду (сейчас они слишком велики и накладываются друг на друга).
Я пытаюсь использовать функцию для изменения размера каждого изображения, когда оно рисуется, но я получаю ошибки при вызове функции, хотя программа компилируется и работает нормально (за исключением изображения, неизменение размера).Функция изменения размера и функции инициализации:
-(UIImage *)resizeImage:(UIImage *)image width:(int)width height:(int)height {
NSLog(@"resizing");
CGImageRef imageRef = [image CGImage];
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef);
//if (alphaInfo == kCGImageAlphaNone)
alphaInfo = kCGImageAlphaNoneSkipLast;
CGContextRef bitmap = CGBitmapContextCreate(NULL, width, height, CGImageGetBitsPerComponent(imageRef),
4 * width, CGImageGetColorSpace(imageRef), alphaInfo);
CGContextDrawImage(bitmap, CGRectMake(0, 0, width, height), imageRef);
CGImageRef ref = CGBitmapContextCreateImage(bitmap);
UIImage *result = [UIImage imageWithCGImage:ref];
CGContextRelease(bitmap);
CGImageRelease(ref);
return result;
}
- (void)viewDidLoad {
UIImage *h1 = [UIImage imageNamed:@"h1.png"];
h1 = [self resizeImage:h1 width:50 height: 50];
UIImageView *h1View = [[UIImageView alloc] initWithImage:h1];
NSArray *imageViewArray = [[NSArray alloc] initWithObjects:
h1View, nil];
NSString *fieldName = [[NSString alloc] initWithFormat:@"column1"];
[self setValue:imageViewArray forKey:fieldName];
[fieldName release];
[imageViewArray release];
[h1View release];
}
Вывод на консоль:
TabTemplate [29322: 207] resizing
TabTemplate [29322]: CGBitmapContextCreate: unsupportedcolorspace
TabTemplate [29322]: CGContextDrawImage: недопустимый контекст
TabTemplate [29322]: CGBitmapContextCreateImage: недопустимый контекст
Я не могу понять, что происходит не так.Любая помощь с благодарностью.