日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

关于图片以及格式UTI

發布時間:2024/1/8 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 关于图片以及格式UTI 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Uniform Type Identifiers?

定義:http://www.escape.gr/manuals/qdrop/UTI.html?

使用UTI獲取圖片格式:

ALAssetRepresentation *assetRep = [asset defaultRepresentation]; NSString *mediaType = [assetRep UTI];

?

最近做了一個模塊,需要獲取到ios 圖片的詳細屬性:包括創建時間,文件格式等等。由于AALsset中,包含的內容不詳細,只好自己去獲取。查詢到需要使用ImageIO接口

首先要導入?AssetsLibrary.framework?and?ImageIO.framework.

代碼部分:

#import <ImageIO/ImageIO.h> - (NSString *)infoFromImageIO:(ALAssetRepresentation *)assetRep {NSMutableData *imgData = nil;NSString *mediaType = [assetRep UTI];// create a buffer to hold image datauint8_t *buffer = (Byte*)malloc(assetRep.size);NSUInteger length = [assetRep getBytes:buffer fromOffset:0.0 length:assetRep.size error:nil];if (length > 0){imgData = [[NSMutableData alloc] initWithBytesNoCopy:buffer length:length freeWhenDone:YES];}// identify image type (jpeg, png, RAW file, ...) using UTI hintNSDictionary* sourceOptionsDict = [NSDictionary dictionaryWithObjectsAndKeys:(id)[assetRep UTI] ,kCGImageSourceTypeIdentifierHint,nil];// create CGImageSource with NSDataCGImageSourceRef sourceRef = CGImageSourceCreateWithData((CFDataRef)imgData, ( CFDictionaryRef) sourceOptionsDict);// get imagePropertiesDictionary CFDictionaryRef imagePropertiesDictionary;imagePropertiesDictionary = CGImageSourceCopyPropertiesAtIndex(sourceRef,0, NULL);// get exif dataCFDictionaryRef exif = (CFDictionaryRef)CFDictionaryGetValue(imagePropertiesDictionary, kCGImagePropertyExifDictionary);NSDictionary *exif_dict = (NSDictionary*)exif;if (exif_dict && [exif_dict count] > 0){//獲取創建時間NSString *createTime = [NSString stringWithString:[exif_dict objectForKey:@"DateTimeOriginal"]];CFRelease(imagePropertiesDictionary);CFRelease(sourceRef);return createTime;}return nil; #if 0// save image WITH meta dataNSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];NSURL *fileURL = nil;CGImageRef imageRef = CGImageSourceCreateImageAtIndex(sourceRef, 0, imagePropertiesDictionary);if (![[sourceOptionsDict objectForKey:@"kCGImageSourceTypeIdentifierHint"] isEqualToString:@"public.tiff"]){fileURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@.%@",documentsDirectory,@"myimage",[[[sourceOptionsDict objectForKey:@"kCGImageSourceTypeIdentifierHint"] componentsSeparatedByString:@"."] objectAtIndex:1]]];CGImageDestinationRef dr = CGImageDestinationCreateWithURL ((__bridge CFURLRef)fileURL,(__bridge CFStringRef)[sourceOptionsDict objectForKey:@"kCGImageSourceTypeIdentifierHint"],1,NULL);CGImageDestinationAddImage(dr, imageRef, imagePropertiesDictionary);CGImageDestinationFinalize(dr);CFRelease(dr);}else{NSLog(@"no valid kCGImageSourceTypeIdentifierHint found …");}// clean up CFRelease(imageRef);CFRelease(imagePropertiesDictionary);CFRelease(sourceRef); #endif }

因為我這個接口只需要獲取時間,故屏蔽了一部分代碼,使用屏蔽部分的內容可以將相冊中的圖片保存到我們自己應用的沙盒中。

?

轉載于:https://www.cnblogs.com/Peterahan/p/3261617.html

總結

以上是生活随笔為你收集整理的关于图片以及格式UTI的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。