您的位置:首页 > 其它

如何获取iPhone拍摄的png照片的拍摄时间,位置信息等图片属性?

2012-08-08 18:04 756 查看
http://www.cocoachina.com/bbs/simple/?t103913.html

如何获取iPhone拍摄的png照片的拍摄时间,位置信息等图片属性?

png格式中可以存储一些辅助信息(ancillary information)

这个特性可用来在图像文件中存储一些文本注释信息。

独立于计算机软硬件环境。

使用无损压缩。

PNG文件格式中要增加下列GIF文件格式所没有 的特性:

每个像素为48位的真彩色图像。

每个像素为16位的灰度图像。

可为灰度图和真彩色图添加α通道。

添加图像的γ信息。

使用循环冗余码(cyclic redundancy code,CRC)检测损害的文件。

加快图像显示的逐次逼近显示方式。

标准的读/写工具包。

但是现在有png格式的照片,我如何从照片中读取拍摄时间和位置信息等图片的属性呢?

还有在拍照的时候需要程序中写代码将这些信息写入到照片中吗?
dengyanjun2012-05-23 15:31
可以吗可以吗可以吗,求~~

ad46212012-06-05 16:10
- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info {

//给照片添加GPS信息并保存到相册

if(picker.sourceType == UIImagePickerControllerSourceTypeCamera)

{

//图片

UIImage *image= [info objectForKey:UIImagePickerControllerOriginalImage];

//元数据

NSDictionary *dict = [info objectForKey:UIImagePickerControllerMediaMetadata];

NSMutableDictionary *metadata=[NSMutableDictionary dictionaryWithDictionary:dict];

//EXIF数据

NSMutableDictionary *EXIFDictionary =[[metadata objectForKey:(NSString *)kCGImagePropertyExifDictionary]mutableCopy];

//GPS数据

NSMutableDictionary *GPSDictionary = [[metadata objectForKey:(NSString *)kCGImagePropertyGPSDictionary]mutableCopy];

if(!EXIFDictionary) {

EXIFDictionary = [NSMutableDictionary dictionary];

[EXIFDictionary setValue:@"xml_user_comment" forKey:(NSString *)kCGImagePropertyExifUserComment];

[metadata setObject:EXIFDictionary forKey:(NSString *)kCGImagePropertyExifDictionary];

}

if(!GPSDictionary) {

/* 请使用CLLocationManager 获取当前拍照的GPS信息*/

// 使用CLLocationManager获取当前位置的CLLocation对象

CLLocation *location=....;

//将CLLocation对象转化为如下格式的NSDictionary

NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

[formatter setTimeZone:timeZone];

[formatter setDateFormat:@"HH:mm:ss.SS"];

NSDictionary *gpsDict = [NSDictionary dictionaryWithObjectsAndKeys:

[NSNumber numberWithFloat:fabs(location.coordinate.latitude)], kCGImagePropertyGPSLatitude,

((location.coordinate.latitude >= 0) ? @"N" : @"S"), kCGImagePropertyGPSLatitudeRef,

[NSNumber numberWithFloat:fabs(location.coordinate.longitude)], kCGImagePropertyGPSLongitude,

((location.coordinate.longitude >= 0) ? @"E" : @"W"), kCGImagePropertyGPSLongitudeRef,

[formatter stringFromDate:[location times*****p]], kCGImagePropertyGPSTimeS*****p,

nil];

//将GPS数据写入图片并保存到相册

if (info && [info objectForKey:UIImagePickerControllerMediaMetadata] && gpsDict) {

[[info objectForKey:UIImagePickerControllerMediaMetadata] setValue:gpsDict forKey:(NSString*)kCGImagePropertyGPSDictionary];

}

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

ALAssetsLibraryWriteImageCompletionBlock imageWriteCompletionBlock =

^(NSURL *newURL, NSError *error) {

if (error) {

NSLog( @"Error writing image with metadata to Photo Library: %@", error );

} else {

NSLog( @"Wrote image with metadata to Photo Library");

}

};

//保存相片到相册 注意:必须使用[image CGImage]不能使用强制转换: (__bridge CGImageRef)image,否则保存照片将会报错

[library writeImageToSavedPhotosAlbum:[image CGImage]

metadata:metadata

completionBlock:imageWriteCompletionBlock];

}

}

//从相册中选择一张照片获取它的GPS信息

else if(picker.sourceType == UIImagePickerControllerSourceTypePhotoLibrary){

__block UIImage *image= [info objectForKey:UIImagePickerControllerOriginalImage];

self.siteImg=image;

__block NSMutableDictionary *imageMetadata = nil;

NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

[library assetForURL:assetURL

resultBlock:^(ALAsset *asset) {

imageMetadata = [[NSMutableDictionary alloc] initWithDictionary:asset.defaultRepresentation.metadata];

NSDictionary *GPSDict=[imageMetadata objectForKey:(NSString*)kCGImagePropertyGPSDictionary];

/* GPSDict 里面即是照片的GPS信息,具体可以输出看看*/

}

failureBlock:^(NSError *error) {

}];

}

[picker dismissModalViewControllerAnimated: YES];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iPhone 如何