iOS保存图片信息到相册

首先要引入ALAssetsLibrary库。

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

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

NSData *imageData = UIImageJPEGRepresentation(image, 0.5);
         
         CLLocation *location = [[CLLocation alloc] initWithLatitude:latitude.doubleValue longitude:longitude.doubleValue];
         NSDictionary *locationDictionary = [Utility getGPSDictionaryForLocation:location];
         
         NSDate *shootTime = [NSDate date];
         NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
         [dateFormatter setDateFormat:@"yyyy:MM:dd HH:mm:ss"];
         NSString *strDate = [dateFormatter stringFromDate:shootTime];
         
         NSDictionary *metaDic = [NSDictionary dictionaryWithObjectsAndKeys:currentLocation, (NSString*)kCGImagePropertyGPSDictionary, [NSDictionary dictionaryWithObject:strDate forKey:(NSString *)kCGImagePropertyTIFFDateTime], (NSString *)kCGImagePropertyTIFFDictionary, nil];
         
         ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
         [library writeImageDataToSavedPhotosAlbum:imageData metadata:metaDic completionBlock:nil];
         [library release];
         [location release];

posted on 2012-11-16 17:34  无量少年  阅读(676)  评论(0编辑  收藏  举报

导航