注释过的反汇编代码: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. Ehcache中配置详解

    <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLoc ...

  2. 【Linux】鸟哥的Linux私房菜基础学习篇整理(九)

    1. quotacheck [-avugfM] [/mount_point]:扫描文件系统并创建Quota配置文件.参数:-a:扫描所有在/etc/mtab内,含有quota支持的文件系统,加上此参数 ...

  3. java学习之面向对象概念

    思考的两种方式: 举例: 把大象放到冰箱里 一.面向过程 :[打开冰箱->把大象放里面->关上冰箱门]面向过程注重的是过程,也就是(动作[函数]),然后按照动作依次去执行就好了. 代表语言 ...

  4. svn图形客户端:smartsvn,svnmanager,rapidsvn,svnworkbench,rabbitsvn,Esvn, trac

    svn图形客户端: smartsvn,http://www.oschina.net/p/smartsvn, 不用安装直接运行 qsvn, http://www.oschina.net/p/qsvn r ...

  5. 【Fiddler】手机抓包

    Fiddler (四) 实现手机的抓包 手机配置了后,Fiddler不开起来就什么也连接不了

  6. 【转】android颜色对应的xml配置值

    原文网址:http://www.cnblogs.com/etgyd/archive/2011/04/02/2003778.html android颜色对应的xml配置值 <?xml versio ...

  7. (转载)php数组删除元素各种方法总结

    (转载)http://www.111cn.net/phper/php/46865.htm 有很多朋友都不知道怎么把数组中元素给删除,下面我来总结各种数组删除元素方法给各位,有需要了解的朋友可进入参考. ...

  8. 线性代数(矩阵乘法):POJ 2778 DNA Sequence

    DNA Sequence   Description It's well known that DNA Sequence is a sequence only contains A, C, T and ...

  9. Android 屏幕截图

    1.同时按下电源键+音量下键截屏 PhoneWindowManager.java private void interceptScreenshotChord() { if (mScreenshotCh ...

  10. 《傲慢与偏见》(Pride and Prejudice)

    <傲慢与偏见>(Pride and Prejudice)改编自英国作家简·奥斯汀的同名小说,1940年上映.讲述了19世纪初期英国的一个普通的中产家庭中五姐妹的爱情与择偶故事.片中因为男主 ...