forked from McZonk/UIKitPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIImage+UIPMetadata.m
68 lines (52 loc) · 1.42 KB
/
UIImage+UIPMetadata.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// UIImage+UIPMetadata.m
//
// Created by Maximilian Christ on 21/11/13.
// Copyright (c) 2013 Boinx Software Ltd. All rights reserved.
//
#import "UIImage+UIPMetadata.h"
#import <ImageIO/ImageIO.h>
@implementation UIImage (UIPMetadata)
+ (NSDictionary *)metadataFromImageData:(NSData *)data
{
if(data == nil)
{
return nil;
}
NSDictionary *metadata = nil;
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, nil);
if(source != nil)
{
metadata = CFBridgingRelease(CGImageSourceCopyPropertiesAtIndex(source, 0, nil));
CFRelease(source);
}
return metadata;
}
+ (NSMutableDictionary *)mutableMetadataFromImageData:(NSData *)data
{
NSDictionary *metadata = [self metadataFromImageData:data];
if(metadata == nil)
{
return nil;
}
return [self mutableMetadataFromMetaData:metadata];
}
+ (NSMutableDictionary *)mutableMetadataFromMetaData:(NSDictionary *)metadata
{
NSMutableDictionary *mutableMetadata = [[NSMutableDictionary alloc] initWithCapacity:metadata.count];
for(NSDictionary *propertyName in metadata)
{
NSDictionary *properties = metadata[propertyName];
if([properties isKindOfClass:NSDictionary.class])
{
NSMutableDictionary *mutableProperties = [[NSMutableDictionary alloc] initWithDictionary:properties];
mutableMetadata[propertyName] = mutableProperties;
}
else
{
mutableMetadata[propertyName] = properties;
}
}
return mutableMetadata;
}
@end