久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何將 exif 元數據寫入圖像(不是相機膠卷,只是

How to write exif metadata to an image (not the camera roll, just a UIImage or JPEG)(如何將 exif 元數據寫入圖像(不是相機膠卷,只是 UIImage 或 JPEG))
本文介紹了如何將 exif 元數據寫入圖像(不是相機膠卷,只是 UIImage 或 JPEG)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我知道如何使用 ALAssets 保存元數據.但是,我想保存圖像,或將其上傳到某個地方,exif 完好無損.我有 exif 數據作為 NSDictionary.但是我怎樣才能將它正確地注入 UIImage(或者可能是 NSData JPEG 表示)?

I am aware of how to save metadata using ALAssets. But, I want to save an image, or upload it somewhere, with exif intact. I have exif data as an NSDictionary. But how can I inject it properly into a UIImage (or probably an NSData JPEG representation)?

推薦答案

UIImage 不包含元數據信息(被剝離).因此,如果您想在不使用 imagepicker 方法的情況下保存它(不在相機膠卷中):

UIImage does not contain metadata information (it is stripped). So if you want to save it without using the imagepicker method (not in camera roll):

按照此處的答案寫入元數據完整的文件:

Follow the answer here to write to a file with the metadata intact:

圖片的exif數據設置問題

不知道為什么會被否決,但方法如下:

no idea why would this be downvoted but here is the method:

在這種情況下,我通過 AVFoundation 獲取圖像,這就是

In this case im getting the image through AVFoundation and this is what goes in the

[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:videoConnection 
                                                     completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error) 
{
    // code here
}

塊代碼:

    CFDictionaryRef metaDict = CMCopyDictionaryOfAttachments(NULL, imageSampleBuffer, kCMAttachmentMode_ShouldPropagate);

    CFMutableDictionaryRef mutable = CFDictionaryCreateMutableCopy(NULL, 0, metaDict);

    // Create formatted date
    NSTimeZone      *timeZone   = [NSTimeZone timeZoneWithName:@"UTC"];
    NSDateFormatter *formatter  = [[NSDateFormatter alloc] init]; 
    [formatter setTimeZone:timeZone];
    [formatter setDateFormat:@"HH:mm:ss.SS"];

    // Create GPS Dictionary
    NSDictionary *gpsDict   = [NSDictionary dictionaryWithObjectsAndKeys:
                               [NSNumber numberWithFloat:fabs(loc.coordinate.latitude)], kCGImagePropertyGPSLatitude
                               , ((loc.coordinate.latitude >= 0) ? @"N" : @"S"), kCGImagePropertyGPSLatitudeRef
                               , [NSNumber numberWithFloat:fabs(loc.coordinate.longitude)], kCGImagePropertyGPSLongitude
                               , ((loc.coordinate.longitude >= 0) ? @"E" : @"W"), kCGImagePropertyGPSLongitudeRef
                               , [formatter stringFromDate:[loc timestamp]], kCGImagePropertyGPSTimeStamp
                               , [NSNumber numberWithFloat:fabs(loc.altitude)], kCGImagePropertyGPSAltitude
                               , nil];  

    // The gps info goes into the gps metadata part

    CFDictionarySetValue(mutable, kCGImagePropertyGPSDictionary, (__bridge void *)gpsDict);

    // Here just as an example im adding the attitude matrix in the exif comment metadata

    CMRotationMatrix m = att.rotationMatrix;
    GLKMatrix4 attMat = GLKMatrix4Make(m.m11, m.m12, m.m13, 0, m.m21, m.m22, m.m23, 0, m.m31, m.m32, m.m33, 0, 0, 0, 0, 1);

    NSMutableDictionary *EXIFDictionary = (__bridge NSMutableDictionary*)CFDictionaryGetValue(mutable, kCGImagePropertyExifDictionary);

    [EXIFDictionary setValue:NSStringFromGLKMatrix4(attMat) forKey:(NSString *)kCGImagePropertyExifUserComment];

    CFDictionarySetValue(mutable, kCGImagePropertyExifDictionary, (__bridge void *)EXIFDictionary);

    NSData *jpeg = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer] ;

在此代碼之后,您將在 jpeg nsdata 中獲得您的圖像,并在可變 cfdictionary 中獲得該圖像的對應字典.

After this code you will have your image in the jpeg nsdata and the correspoding dictionary for that image in the mutable cfdictionary.

你現在要做的就是:

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

    CFStringRef UTI = CGImageSourceGetType(source); //this is the type of image (e.g., public.jpeg)

    NSMutableData *dest_data = [NSMutableData data];


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

    if(!destination) {
        NSLog(@"***Could not create image destination ***");
    }

    //add the image contained in the image source to the destination, overidding the old metadata with our modified metadata
    CGImageDestinationAddImageFromSource(destination,source,0, (CFDictionaryRef) mutable);

    //tell the destination to write the image data and metadata into our data object.
    //It will return false if something goes wrong
    BOOL success = CGImageDestinationFinalize(destination);

    if(!success) {
        NSLog(@"***Could not create data from image destination ***");
    }

    //now we have the data ready to go, so do whatever you want with it
    //here we just write it to disk at the same path we were passed

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
    NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"ImagesFolder"];

    NSError *error;
    if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
        [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]; //Create folder

    //    NSString *imageName = @"ImageName";

    NSString *fullPath = [dataPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg", name]]; //add our image to the path

    [dest_data writeToFile:fullPath atomically:YES];

    //cleanup

    CFRelease(destination);
    CFRelease(source);

請注意我不是使用 ALAssets 而是直接保存到我選擇的文件夾中.

Note how I'm not saving using the ALAssets but directly into a folder of my choice.

順便說一句,大部分代碼都可以在我最初發布的鏈接中找到.

Btw most of this code can be found in the link I posted at first.

這篇關于如何將 exif 元數據寫入圖像(不是相機膠卷,只是 UIImage 或 JPEG)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Using Instruments to test an iOS app without having source code to the application(在沒有應用程序源代碼的情況下使用 Instruments 測試 iOS 應用程序)
KIF: How to auto-run/stress test an iOS app to find the cause of a rare UI bug?(KIF:如何自動運行/壓力測試 iOS 應用程序以找出罕見 UI 錯誤的原因?)
Can#39;t change target membership visibility in Xcode 4.5(無法更改 Xcode 4.5 中的目標成員身份可見性)
UITableView: Handle cell selection in a mixed cell table view static and dynamic cells(UITableView:在混合單元格表視圖靜態和動態單元格中處理單元格選擇)
How to remove Address Bar in Safari in iOS?(如何在 iOS 中刪除 Safari 中的地址欄?)
iOS 5 SDK is gone after upgrade to Xcode 4.5(升級到 Xcode 4.5 后,iOS 5 SDK 消失了)
主站蜘蛛池模板: 中文字幕在线人 | 国产成人在线一区 | 成人av大全| 色欧美片视频在线观看 | 狠狠狠色丁香婷婷综合久久五月 | 亚洲人成人一区二区在线观看 | 国产精品永久免费 | 国产91在线观看 | 久久久久国产 | 黄色成人亚洲 | 免费久久精品视频 | 国产男人的天堂 | 秋霞在线一区二区 | 午夜精品一区二区三区在线观看 | 精品三级在线观看 | 欧美一区二区三区大片 | eeuss国产一区二区三区四区 | 天天干天天插天天 | 日韩欧美在线精品 | 99久久精品免费看国产高清 | 午夜电影福利 | www.久久久久久久久久久久 | 免费三级网 | 亚洲成人自拍 | 天天曰天天干 | 欧美成人精品一区二区男人看 | 国产区在线看 | 国产精品免费一区二区 | 日本 欧美 国产 | 欧美日韩视频一区二区 | 又爽又黄axxx片免费观看 | 亚洲欧美日韩精品久久亚洲区 | 久久久久久久久久久久久久国产 | 97精品国产| 国产在线观看网站 | av免费电影在线 | 国产精品久久久久久久7电影 | 亚洲看片网站 | 精品国产乱码久久久久久牛牛 | 99久久免费精品国产男女高不卡 | 国产欧美一区二区三区久久手机版 |