码迷,mamicode.com
首页 > 其他好文 > 详细

UIImage附加信息(exif)..

时间:2015-06-04 20:43:45      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

//惨痛经历,,,

- (void)saveToAlbumWithImage:(UIImage*)image

             completionBlock:(void (^)(NSURL *assetURL))completionBlock

                failureBlock:(void (^)(NSError *error))failureBlock

{

    NSData* pngData =  UIImagePNGRepresentation(image);

    

    CGImageSourceRef source = CGImageSourceCreateWithData((__bridge_retained CFDataRef)pngData, NULL);

 

    NSDictionary *metadata = (__bridge NSDictionary *)(CGImageSourceCopyPropertiesAtIndex(source, 0, NULL));

    

    NSMutableDictionary *metadataAsMutable = [[NSMutableDictionary dictionaryWithDictionary:metadata] mutableCopy];

    

    //For EXIF Dictionary

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

    if(!EXIFDictionary)

        EXIFDictionary = [NSMutableDictionary dictionary];

    

    [EXIFDictionary setObject:@"200x300-1....." forKey:(NSString*)kCGImagePropertyExifUserComment];

    

    //add our modified EXIF data back into the image’s metadata

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

    

    CFStringRef UTI = CGImageSourceGetType(source);

    

    NSMutableData *dest_data = [NSMutableData data];

    CGImageDestinationRef destination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)dest_data, UTI, 1, NULL);

    

    if(destination)

    {

        CGImageDestinationAddImageFromSource(destination, source, 0, (__bridge CFDictionaryRef) metadataAsMutable);

        BOOL success = CGImageDestinationFinalize(destination);

        if(success)

        {

            //            CIImage *testImage = [CIImage imageWithData:dest_data];

            //

            //            NSDictionary *propDict = [testImage properties];//////////............由此应可知以上无误,,,,,,,

            //

            //            UIImage *newImage = [UIImage imageWithData:dest_data];

            //            NSData* pngData1 =  UIImagePNGRepresentation(newImage);

            //

            //            CGImageSourceRef source1 = CGImageSourceCreateWithData((CFDataRef)pngData1, NULL);

            //            NSDictionary *metadata1 = (__bridge NSDictionary *)(CGImageSourceCopyPropertiesAtIndex(source1, 0, NULL));

            //

            NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];

            NSString *appName = [infoDictionary objectForKey:@"CFBundleDisplayName"];

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

////////metadataAsMutable.............定位到问题,,,,,,,

//////............衡量标准,,,,,,,,,,,,,.......

            [assets1Library saveImage:image.CGImage metadata:metadataAsMutable toAlbum:appName completion:^(NSURL *assetURL, NSError *error) {//////...........苹果的角度..,,,,,,,,

                completionBlock(assetURL);

                if(destination)

                    CFRelease(destination);

                CFRelease(source);

            } failure:failureBlock];

        }

    }

}

UIImage附加信息(exif)..

标签:

原文地址:http://www.cnblogs.com/goahead-yingjun/p/4552729.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!