gpt4 book ai didi

iphone - UIImage 元数据

转载 作者:可可西里 更新时间:2023-11-01 03:27:51 28 4
gpt4 key购买 nike

在我的应用程序中,我正在从 Assets 库中检索 UIImage,该图像具有元数据。然后,该应用程序会调整图像大小并旋转图像,从而创建新图像。新图像没有预期的原始元数据,但如何在上传前将元数据添加回图像?

提前致谢!

最佳答案

我自己修复了它,这是我使用的一种方法,以防其他人想知道如何去做! :)

-(UIImage *)addMetaData:(UIImage *)image {

NSData *jpeg = [NSData dataWithData:UIImageJPEGRepresentation(image, 1.0)];

CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)jpeg, NULL);

NSDictionary *metadata = [[asset_ defaultRepresentation] metadata];

NSMutableDictionary *metadataAsMutable = [metadata mutableCopy];

NSMutableDictionary *EXIFDictionary = [metadataAsMutable objectForKey:(NSString *)kCGImagePropertyExifDictionary];
NSMutableDictionary *GPSDictionary = [metadataAsMutable objectForKey:(NSString *)kCGImagePropertyGPSDictionary];
NSMutableDictionary *TIFFDictionary = [metadataAsMutable objectForKey:(NSString *)kCGImagePropertyTIFFDictionary];
NSMutableDictionary *RAWDictionary = [metadataAsMutable objectForKey:(NSString *)kCGImagePropertyRawDictionary];
NSMutableDictionary *JPEGDictionary = [metadataAsMutable objectForKey:(NSString *)kCGImagePropertyJFIFDictionary];
NSMutableDictionary *GIFDictionary = [metadataAsMutable objectForKey:(NSString *)kCGImagePropertyGIFDictionary];

if(!EXIFDictionary) {
EXIFDictionary = [NSMutableDictionary dictionary];
}

if(!GPSDictionary) {
GPSDictionary = [NSMutableDictionary dictionary];
}

if (!TIFFDictionary) {
TIFFDictionary = [NSMutableDictionary dictionary];
}

if (!RAWDictionary) {
RAWDictionary = [NSMutableDictionary dictionary];
}

if (!JPEGDictionary) {
JPEGDictionary = [NSMutableDictionary dictionary];
}

if (!GIFDictionary) {
GIFDictionary = [NSMutableDictionary dictionary];
}

[metadataAsMutable setObject:EXIFDictionary forKey:(NSString *)kCGImagePropertyExifDictionary];
[metadataAsMutable setObject:GPSDictionary forKey:(NSString *)kCGImagePropertyGPSDictionary];
[metadataAsMutable setObject:TIFFDictionary forKey:(NSString *)kCGImagePropertyTIFFDictionary];
[metadataAsMutable setObject:RAWDictionary forKey:(NSString *)kCGImagePropertyRawDictionary];
[metadataAsMutable setObject:JPEGDictionary forKey:(NSString *)kCGImagePropertyJFIFDictionary];
[metadataAsMutable setObject:GIFDictionary forKey:(NSString *)kCGImagePropertyGIFDictionary];

CFStringRef UTI = CGImageSourceGetType(source);

NSMutableData *dest_data = [NSMutableData data];

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

//CGImageDestinationRef hello;

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

BOOL success = NO;
success = CGImageDestinationFinalize(destination);

if(!success) {
}

dataToUpload_ = dest_data;

CFRelease(destination);
CFRelease(source);

return image;
}

关于iphone - UIImage 元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10582829/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com