У меня есть простое приложение для iPhone, которое позволяет пользователю загружать изображения на сервер. Проблема в том, что, если они загружают большой файл изображения. Я хочу ограничить его (максимум) 200 КБ. Я что-то запустил, но, похоже, в моем while
вылетает ошибка.
Вот код:
NSString *jpgPath = [NSString stringWithFormat:@"Documents/%@",sqlImageUploadPathTwo];
NSString *jpgPathTwo = [NSString stringWithFormat:@"./../Documents/%@",sqlImageUploadPathTwo];
NSString *yourPath = [NSHomeDirectory() stringByAppendingPathComponent:jpgPath];
NSLog(@"yourPath: %@", yourPath);
NSFileManager *man = [[NSFileManager alloc] init];
NSDictionary *attrs = [man attributesOfItemAtPath: yourPath error: NULL];
int *result = [attrs fileSize];
NSLog(@"Here's the original size: %d", result);
NSLog(@"jpgPath: %@ // jpgPathTwo: %@", jpgPath, jpgPathTwo);
while (result > 9715) {
UIImage *tempImage = [UIImage imageNamed: jpgPath];
NSData *imageData = [NSData dataWithData:UIImageJPEGRepresentation(tempImage, 0.9)];
[imageData writeToFile:jpgPathTwo atomically:YES];
NSLog(@"just shrunk it once.");
}
NSLog(@"SIZE AFTER SHRINK: %@", result);
Спасибо!
Коултон