【发布时间】:2013-05-12 13:52:57
【问题描述】:
我正在关注this 关于如何调整图像大小的帖子。我把+ (UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize;放在selectExerciseImageViewController.h里面,把相关代码复制到selectExerciseImageViewController.m。
然后我尝试调整图像大小,保存它,并将保存的图像文件检索到UIImageView。但由于某种原因,图像从未显示UIImageView,最后一个NSLog 返回null
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
UIImage* newImage = [selectExerciseImageViewController imageWithImage:[info objectForKey:@"UIImagePickerControllerOriginalImage"]
scaledToSizeWithSameAspectRatio:CGSizeMake(40.0,40.0)];
NSData* imageData = UIImagePNGRepresentation(newImage);
// Give a name to the file
NSString* imageName = @"MyImage.png";
// Now, we have to find the documents directory so we can save it
// Note that you might want to save it elsewhere, like the cache directory,
// or something similar.
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
// Now we get the full path to the file
NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];
// and then we write it out
[imageData writeToFile:fullPathToFile atomically:NO];
//imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
_testimg.image = [UIImage imageNamed:@"MyImage.png"];
NSLog(@"asd %@",[UIImage imageNamed:@"MyImage.png"]);
}
【问题讨论】:
标签: ios cocoa-touch uiimagepickercontroller