![](/img/trans.png)
[英]iOS - UIImageView - how to handle UIImage image orientation
[英]How to get Image Orientation without loading the UIImage?
我的問題很簡單,我想獲取圖像的方向,但是我不想使用[UIImage imageWithData:]
因為它會消耗內存並且速度可能很慢。 那么,解決方案是什么? 圖像保存在應用程序的documents文件夾中,而不是ALAssetsLibrary
。
PS:新年快樂!
您需要使用較低級別的Quartz功能。 將圖像的前2K或4K讀入NSData對象,然后將該數據傳遞給增量圖像創建者,並詢問其方向。 如果您不明白,請大塊閱讀。 JPG幾乎總是在數據的前2K中具有元數據(也許是4K,自從我編寫這段代碼以來已經有一段時間了):
{
CGImageSourceRef imageSourcRef = CGImageSourceCreateIncremental(NULL);
CGImageSourceUpdateData(imageSourcRef, (__bridge CFDataRef)data, NO);
CFDictionaryRef dict = CGImageSourceCopyPropertiesAtIndex(imageSourcRef, 0, NULL);
if(dict) {
//CFShow(dict);
self.properties = CFBridgingRelease(dict);
if(!self.orientation) {
self.orientation = [[self.properties objectForKey:@"Orientation"] integerValue];
}
}
CFRelease(imageSourcRef);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.