我正在编写一个应用程序,让用户可以选择调整他们拍摄的图像大小并将其上传到服务。调整大小似乎工作正常,但它没有将重新创建的图像存储在适当的位置,因为应用程序似乎不认为有照片加载。
请注意,if 语句中的第一个函数(关于“normal_size”)工作正常。我试图在附加大小参数中重新创建这两行,但我似乎无法弄清楚为什么它不存储它。这真让我抓狂。这是代码:
// Set image dictionaries
iInfoDict = [[NSDictionary alloc] initWithDictionary:info];
NSLog(@"infor ===== %@", info);
UIImage* image =[info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSLog(@"iImage name === %@", iImage);
// Determines path of image taken / chosen
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"image.jpg"];
CGSize size;
// Not sure what this does other than dismissing the pickerViewController
NSData* data = UIImageJPEGRepresentation(image, 0.9);
[data writeToFile:appFile options:nil error:nil];
NSLog(@"Documents ==== %@", documentsDirectory);
[picker dismissModalViewControllerAnimated:YES];
// photo.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
// IMAGE RESIZE CODE
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"normal_image"])
{
[photoData setObject:[iInfoDict objectForKey:@"UIImagePickerControllerOriginalImage"] forKey:@"image"];
photo.image = [iInfoDict objectForKey:@"UIImagePickerControllerOriginalImage"];
}
else if ([[NSUserDefaults standardUserDefaults] boolForKey:@"small_image"])
{
CGSize size = CGSizeMake (600, 450);
UIImage *origImage = [iInfoDict objectForKey:@"UIImagePickerControllerOriginalImage"];
UIImage *destImage = [origImage resizedImage:size interpolationQuality:kCGInterpolationHigh];
NSLog(@"Image Size: %@", NSStringFromCGSize(destImage.size));
[photoData setObject:destImage forKey:@"image"];
photo.image = destImage;
}