iOS保存图片信息到相册

首先要引入ALAssetsLibrary库。

其次要用户授予定位服务权限。

保存附加信息到相册到代码如下:

 1 NSData *imageData = UIImageJPEGRepresentation(image, 0.5);
 2         
 3         CLLocation *location = [[CLLocation alloc] initWithLatitude:latitude.doubleValue longitude:longitude.doubleValue];
 4         NSDictionary *locationDictionary = [Utility getGPSDictionaryForLocation:location];
 5         
 6         NSDate *shootTime = [NSDate date];
 7         NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
 8         [dateFormatter setDateFormat:@"yyyy:MM:dd HH:mm:ss"];
 9         NSString *strDate = [dateFormatter stringFromDate:shootTime];
10         
11         NSDictionary *metaDic = [NSDictionary dictionaryWithObjectsAndKeys:currentLocation, (NSString*)kCGImagePropertyGPSDictionary, [NSDictionary dictionaryWithObject:strDate forKey:(NSString *)kCGImagePropertyTIFFDateTime], (NSString *)kCGImagePropertyTIFFDictionary, nil];
12         
13         ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
14         [library writeImageDataToSavedPhotosAlbum:imageData metadata:metaDic completionBlock:nil];
15         [library release];
16         [location release];
posted @ 2012-08-02 10:58  大师赵  阅读(1576)  评论(0编辑  收藏  举报