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) p_w_picpathPickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info {     

   //给照片添加GPS信息并保存到相册
    if(picker.sourceType == UIImagePickerControllerSourceTypeCamera)
    {
        //图片
        UIImage *p_w_picpath= [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 p_w_picpathWriteCompletionBlock =
         ^(NSURL *newURL, NSError *error) {
            if (error) {
             NSLog( @"Error writing p_w_picpath with metadata to Photo Library: %@", error );
            } else {
             NSLog( @"Wrote p_w_picpath with metadata to Photo Library");
           }
        };
    
        //保存相片到相册 注意:必须使用[p_w_picpath CGImage]不能使用强制转换: (__bridge CGImageRef)p_w_picpath,否则保存照片将会报错
        [library writeImageToSavedPhotosAlbum:[p_w_picpath CGImage] 
                                 metadata:metadata
                          completionBlock:p_w_picpathWriteCompletionBlock];
        }
    }
   //从相册中选择一张照片获取它的GPS信息
    else  if(picker.sourceType == UIImagePickerControllerSourceTypePhotoLibrary){
        __block UIImage *p_w_picpath= [info objectForKey:UIImagePickerControllerOriginalImage];
        self.siteImg=p_w_picpath;

        __block NSMutableDictionary *p_w_picpathMetadata = nil;            
        NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];            
        ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
        [library assetForURL:assetURL
                 resultBlock:^(ALAsset *asset)  {
                     p_w_picpathMetadata = [[NSMutableDictionary alloc] initWithDictionary:asset.defaultRepresentation.metadata];                         
                     NSDictionary *GPSDict=[p_w_picpathMetadata objectForKey:(NSString*)kCGImagePropertyGPSDictionary];
                     /* GPSDict 里面即是照片的GPS信息,具体可以输出看看*/
                 }
                failureBlock:^(NSError *error) {
                }];
    }    
    [picker dismissModalViewControllerAnimated: YES];
}