注释过的反汇编代码:http://pan.baidu.com/share/link?shareid=3491166579&uk=537224442

伪代码(不精确,仅供参考):

NSString* _UICacheNameForImageAtPath(NSString *imageName,NSBundle *bundle);

NSString* ProductSuffix();

UIImage* GetImageAtPath(NSString *imageFilePath,CGFloat scale);

NSMutableDictionary *gCacheNameToImageMap =nil;

NSMutableDictionary *gImageToCacheNameMap =nil;

BOOL __prefer2xImages = NO;

UIImage *_UIImageAtPath(NSString *imageFileName,NSBundle *mainBundle, BOOL shouldForce1xScale)

{

// imageFileName = @"Default.png"

)

return nil;

// bundleIdentifier_imageFileName

NSString *cacheNameOfImage =_UICacheNameForImageAtPath(imageFileName, mainBundle);

UIImage *resultImage = nil;

if (gCacheNameToImageMap !=nil)

{

resultImage = [gCacheNameToImageMapobjectForKey:cacheNameOfImage];

if (resultImage != nil)

{

if (![resultImage _isCached])

{

[resultImage retain];

}

[resultImage _setCached:YES];

return resultImage;

}

}

else

{

gCacheNameToImageMap = [NSMutableDictionarydictionary];

gImageToCacheNameMap = [NSMutableDictionarydictionary];

}

BOOL force1xScale = NO;

if (__prefer2xImages)

{

force1xScale = shouldForce1xScale;

}

NSString *imageExt = [imageFileNamepathExtension];

)

{

imageExt = @"png";

}

NSString *bundlePath = nil;

if (mainBundle != nil)

{

bundlePath = [mainBundle bundlePath];

}

NSString *productSuffix = ProductSuffix();// ~iphone, ~ipad

NSString *imageNameWithoutSuffix = [imageFileNamestringByReplacingOccurrencesOfString:productSuffixwithString:@""];

// Default

NSString *imageNameWithoutSuffixAndExt = [imageNameWithoutSuffixstringByDeletingPathExtension];

// Default~iphone

NSString *imageNameWithSuffix = [imageNameWithoutSuffixAndExtstringByAppendingString:productSuffix];

// Default@1x

NSString *imageName1x = [imageNameWithoutSuffixAndExtstringByAppendingString:@"@1x"];

// Default@1x~iphone

NSString *imageName1xWithSuffix = [imageName1xstringByAppendingString:productSuffix];

// Default_1only_

NSString *imageName_1only_ = [imageNameWithoutSuffixAndExtstringByAppendingString:@"_1only_"];

// Default_1only_~ipnone

NSString *imageName_1only_WithSuffix = [imageName_1only_stringByAppendingString:productSuffix];

// Default@2x

NSString *imageName2x = [imageNameWithoutSuffixAndExtstringByAppendingString:@"@2x"];

// Default@2x~iphone

NSString *imageName2xWithSuffix = [imageName2xstringByAppendingString:productSuffix];

// Default_2only_@2x

NSString *imageName_2only_2x = [imageNameWithoutSuffixAndExtstringByAppendingString:@"_2only_@2x"];

// Default_2only_@2x~iphone

NSString *imageName_2only_2xWithSuffix = [imageName_2only_2xstringByAppendingString:productSuffix];

NSString *targetFileName =nil;

NSString *targetFilePath =nil;

if (!force1xScale)

{

// Default@2x~iphone.png

targetFileName = [imageName2xWithSuffix stringByAppendingPathExtension:imageExt];

targetFilePath = [bundlePath stringByAppendingPathComponent:targetFileName];

resultImage = GetImageAtPath(targetFilePath,2.0f);

// Default_2only_@2x~iphone.png

if (resultImage == nil)

{

targetFileName = [imageName_2only_2xWithSuffix stringByAppendingPathExtension:imageExt];

targetFilePath = [bundlePath stringByAppendingPathComponent:targetFileName];

resultImage = GetImageAtPath(targetFilePath,2.0f);

}

// Default@2x.png

if (resultImage == nil)

{

targetFileName = [imageName2x stringByAppendingPathExtension:imageExt];

targetFilePath = [bundlePath stringByAppendingPathComponent:targetFileName];

resultImage = GetImageAtPath(targetFilePath,2.0f);

}

// Default_2only_@2x.png

if (resultImage == nil)

{

targetFileName = [imageName_2only_2x stringByAppendingPathExtension:imageExt];

targetFilePath = [bundlePath stringByAppendingPathComponent:targetFileName];

resultImage = GetImageAtPath(targetFilePath,2.0f);

}

}

if (resultImage == nil)

{

// Default~iphone.png

targetFileName = [imageNameWithSuffix stringByAppendingPathExtension:imageExt];

targetFilePath = [bundlePath stringByAppendingPathComponent:targetFileName];

resultImage = GetImageAtPath(targetFilePath,1.0f);

// Default.png

if (resultImage == nil)

{

targetFileName = [imageNameWithoutSuffixAndExt stringByAppendingPathExtension:imageExt];

targetFilePath = [bundlePath stringByAppendingPathComponent:targetFileName];

resultImage = GetImageAtPath(targetFilePath,1.0f);

}

// Default@1x~iphone.png

if (resultImage == nil)

{

targetFileName = [imageName1xWithSuffix stringByAppendingPathExtension:imageExt];

targetFilePath = [bundlePath stringByAppendingPathComponent:targetFileName];

resultImage = GetImageAtPath(targetFilePath,1.0f);

}

// Default_1only_~ipnone.png

if (resultImage == nil)

{

targetFileName = [imageName_1only_WithSuffix stringByAppendingPathExtension:imageExt];

targetFilePath = [bundlePath stringByAppendingPathComponent:targetFileName];

resultImage = GetImageAtPath(targetFilePath,1.0f);

}

// Default@1x.png

if (resultImage == nil)

{

targetFileName = [imageName1x stringByAppendingPathExtension:imageExt];

targetFilePath = [bundlePath stringByAppendingPathComponent:targetFileName];

resultImage = GetImageAtPath(targetFilePath,1.0f);

}

// Default_1only.png

if (resultImage == nil)

{

targetFileName = [imageName_1only_ stringByAppendingPathExtension:imageExt];

targetFilePath = [bundlePath stringByAppendingPathComponent:targetFileName];

resultImage = GetImageAtPath(targetFilePath,1.0f);

}

// Default~iphone

if (resultImage == nil)

{

targetFilePath = [bundlePath stringByAppendingPathComponent:imageNameWithSuffix];

resultImage = GetImageAtPath(targetFilePath,1.0f);

}

// Default

if (resultImage == nil)

{

targetFilePath = [bundlePath stringByAppendingPathComponent:imageNameWithoutSuffixAndExt];

resultImage = GetImageAtPath(targetFilePath,1.0f);

}

}

if (resultImage == nil)

{

if (!force1xScale)

{

// Default@2x.png

targetFilePath = [mainBundle pathForResource:imageName2x ofType:imageExt];

resultImage = GetImageAtPath(targetFilePath,2.0f);

// Default_2only_@2x.png

if (resultImage ==nil)

{

targetFilePath = [mainBundle pathForResource:imageName_2only_2x ofType:imageExt];

resultImage = GetImageAtPath(targetFilePath,2.0f);

}

}

// Default.png

if (resultImage == nil)

{

targetFilePath = [mainBundle pathForResource:imageNameWithoutSuffixAndExt ofType:imageExt];

resultImage = GetImageAtPath(targetFilePath,1.0f);

}

// Default@1x.png

if (resultImage == nil)

{

targetFilePath = [mainBundle pathForResource:imageName1x ofType:imageExt];

resultImage = GetImageAtPath(targetFilePath,1.0f);

}

// Default_1only_.png

if (resultImage == nil)

{

targetFilePath = [mainBundle pathForResource:imageName_1only_ ofType:imageExt];

resultImage = GetImageAtPath(targetFilePath,1.0f);

}

}

if (resultImage != nil)

{

[gCacheNameToImageMap setValue:resultImage forKey:cacheNameOfImage];

[gImageToCacheNameMap setValue:cacheNameOfImage forKey:resultImage];

[resultImage _setNamed:YES];

[resultImage _setCached:YES];

}

return resultImage;

}

逆向iOS SDK -- _UIImageAtPath 的实现(SDK 5.1)的更多相关文章

  1. [Office][C#] NPOI、OpenXML SDK、OpenOffice.org SDK 写入资料到 EXCEL 档案[转]

    原文地址:http://www.dotblogs.com.tw/chou/archive/2010/04/29/14912.aspx 一.簡介 要將資料寫入 EXCEL 檔案有許多的方法,但假如電腦不 ...

  2. Android SDK Tools和Android SDK Platform-tools

    SDK Platform 可以理解为版本,因此有 SDK Platform 7,SDK Platform 8等等Android SDK Tools 是各个版本都可通用的工具文件夹,里面有draw9pa ...

  3. 阿里云SDK手册之java SDK

    进行阿里云sdk开发的前提是已经购买阿里云的相关服务才能调用阿里的相关接口进行开发.最近公司在做云管控的项目,于是进行下摘录总结. 一. 环境准备 阿里云针对不同的开发语言提供不同的sdk,由于项目用 ...

  4. 打开SDK Manager检查Android SDK下载和更新失败的解决方法

    [故障描述] 打开SDK Manager检查Android  SDK状况,出现以下情况: Failed to fetch URL https://dl-ssl.google.com/android/r ...

  5. “AIR SDK 0.0: AIR SDK location “...\devsdks\AIRSDK\Win” does not exist.”问题解决~

    原文同步至:http://www.waylau.com/air-sdk-0-0-air-sdk-location-does-not-exist-address/ 导入AS3项目时提示“AIR SDK ...

  6. Android sdk platform,sdk tools,sdk Build tools,sdk platform tools 的关系

    1. sdk platform 简单理解为系统版本 最新级别: 28:Android 9 27:Android 8.1 26:Android 8.0 25:Android 7.1 24:Android ...

  7. linux===启动sdk manager下载配置sdk的时候报错的解决办法

    当启动sdk manager下载配置sdk的时候,报错如下: botoo@botoo-virtual-machine:/opt/android-sdk-linux/tools$ sudo  ./and ...

  8. windows中android SDK manager安装更新sdk很慢,或者出现Done loading packages后不动甚至没有任何可用包

    出现问题: 1.windows中android SDK manager安装更新sdk很慢,或者出现Done loading packages后不动甚至没有任何可用包 2.Failed to fetch ...

  9. 修改android studio中的avd sdk路径、avd sdk找不到的解决方案

    要进行Android应用程序的开发,首先就要搭建好Android的开发环境,所需要的工具有如下4个:1.java JDK:2.Android SDK:3.Eclipse:4.ADT 1.java JD ...

  10. 轻量易用的微信Sdk发布——Magicodes.Wx.Sdk

    概述 最简洁最易于使用的微信Sdk,包括公众号Sdk.小程序Sdk.企业微信Sdk等,以及Abp VNext集成. GitHub地址:https://github.com/xin-lai/Magico ...

随机推荐

  1. RTF格式文件浅析

    ps:这两天在分析从微软的word复制一个绕排环绕的表格到openoffice的writer中去的bug,需要了解RTF... RTF是Rich TextFormat的缩写,意即多文本格式.这是一种类 ...

  2. iOS cell自动换行

    // //  DynamicHeightsViewController.h //  DynamicHeights // //  Created by Matt Long on 9/22/09. //  ...

  3. Unity 地形

    创建一个地形: GameObject —> Create Other —> Terrain; 地形的属性设置:(部分属性后面有另说,表示其他作者有说明过的内容) Base Terrain( ...

  4. mt7601 driver

    http://download.csdn.net/detail/u011500307/7011649 http://my.oschina.net/fgq611/blog/180750 http://b ...

  5. javascript 路线整理

    前端开发很重要,编写脚本也不容易. 总结我以前的前端学习经历,基本是一团乱麻:css+javascript是在大三自学的,当时自己做课程设计,逼着自己在一个月之内,写了一个半成品的j2ee网站.当时, ...

  6. Jump Game —— LeetCode

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  7. VMware宿主机和虚拟机的网络连接问题

    今天在win8上装了个vmware虚拟机,却发现一个vmware workstation宿主机ping不通centos虚拟机,宿主机和centos虚拟机都可以正常上网. 问题描述:今天在vmware ...

  8. DFS Zoj 2110

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2110 //2110 #include<stdio.h> #in ...

  9. Uncle Sam 山姆大叔

    山姆大叔被用来代指“美国”或“美国政府”,主要在美国.英国,尤其是在新闻界中使用较多.“山姆大叔”是美国的绰号,它同自由女神一样,为世人所熟知. 形象 美国的报纸杂志.文学作品和漫画中,经常可以看到“ ...

  10. 10个经典的Java面试题

    这里有10个经典的Java面试题,也为大家列出了答案.这是Java开发人员面试经常容易遇到的问题,相信你了解和掌握之后一定会有所提高.让我们一起来看看吧. 1.Java的HashMap是如何工作的? ...