0
我正在编写一个应用程序,它允许用户选择调整图像大小并将其上载到服务中。调整大小似乎工作正常,但它不会将重新创建的图像存储在适当的位置,因为应用程序似乎不认为已加载照片。在Objective C中存储重新调整大小的图像
请注意,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;
}
谢谢你的答复。评论的代码是旧的,我还没有删除它。有一种功能将照片推送到服务中,并且它推出的第一件事是一个名为“数据”的字典,似乎在图像调整大小后正在写入数据,但无论出于何种原因,图像当我们将它加载到网站上时,它仍然显示为全尺寸。 –
哦,我的上帝,这是照片。图像而不是写入的图像,这是问题。难以置信的。 –