我UIImagePickerController
在磁盘上使用和保存图像时遇到了很大的性能问题。我无法弄清楚我做错了什么。这是我的代码:
- (void)imagePickerController:(UIImagePickerController *)pick
didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
iPixAppDelegate *delegate = (iPixAppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate addPicture:imageData];
}
该addPicture
方法创建一个以这种方式初始化的新图片对象:
- (Picture*) initPicture:(NSData*)dat inFolder:(NSString*)pat {
self.data = dat;
NSDate *d = [NSDate date];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-mm-dd hh-mm-ss"];
self.name = [[formatter stringFromDate:d] stringByAppendingString:@".png"]; //The name by default of a picture is the date it has been taken
[formatter release];
self.path = [pat stringByAppendingPathComponent:self.name];
if(![self fileExistsAtPath:self.path]){
[self.data writeToFile:self.path atomically:YES];
}
return self;
}
速度非常快,UIImagePickerController
但是当我将图片保存在磁盘上时程序变得非常慢。
知道我做错了什么吗?