cocoa touch——UIImage——create,init
来源:互联网 发布:java获取泛型t的class 编辑:程序博客网 时间:2024/06/05 09:39
create
bundle(cache)
+ (nullable UIImage *)imageNamed:(NSString *)name; // load from main bundle#if __has_include(<UIKit/UITraitCollection.h>)+ (nullable UIImage *)imageNamed:(NSString *)name inBundle:(nullable NSBundle *)bundle compatibleWithTraitCollection:(nullable UITraitCollection *)traitCollection NS_AVAILABLE_IOS(8_0);#endif
注意:
- 前者是后者的特定版本,相当于后者的bundle为nil(main bundle,app),traitCollection为nil(main screen)
- name可能是asset catalogs中的image asset名,也可能是图像文件名
- name是图像文件名时,如果是PNG,可以省略文件扩展名.png,如果是其他格式图像文件,不能省略
- bundle中的图像system cache,提高了图像访问性能,但增加了app 内存消耗
file
+ (nullable UIImage *)imageWithContentsOfFile:(NSString *)path;
NSData
+ (nullable UIImage *)imageWithData:(NSData *)data;+ (nullable UIImage *)imageWithData:(NSData *)data scale:(CGFloat)scale NS_AVAILABLE_IOS(6_0);
Quartz(CGImage)
+ (UIImage *)imageWithCGImage:(CGImageRef)cgImage;+ (UIImage *)imageWithCGImage:(CGImageRef)cgImage scale:(CGFloat)scale orientation:(UIImageOrientation)orientation NS_AVAILABLE_IOS(4_0);
Core Image(CIImage)
#if __has_include(<CoreImage/CoreImage.h>)+ (UIImage *)imageWithCIImage:(CIImage *)ciImage NS_AVAILABLE_IOS(5_0);+ (UIImage *)imageWithCIImage:(CIImage *)ciImage scale:(CGFloat)scale orientation:(UIImageOrientation)orientation NS_AVAILABLE_IOS(6_0);#endif
init
file
- (nullable instancetype)initWithContentsOfFile:(NSString *)path;
注意:
- path必须包含文件扩展名用来识别图像类型(格式)
- 此方法把file的image data加载入内存,并且标记可清除,如果image data在内存中被清除,可以重读path指定的文件重新加载
NSData
- (nullable instancetype)initWithData:(NSData *)data;- (nullable instancetype)initWithData:(NSData *)data scale:(CGFloat)scale NS_AVAILABLE_IOS(6_0);
注意:
- data数据格式必须符合系统支持的图像格式之一
Quartz(CGImage)
- (instancetype)initWithCGImage:(CGImageRef)cgImage;- (instancetype)initWithCGImage:(CGImageRef)cgImage scale:(CGFloat)scale orientation:(UIImageOrientation)orientation NS_AVAILABLE_IOS(4_0);
Core Image(CIImage)
#if __has_include(<CoreImage/CoreImage.h>)- (instancetype)initWithCIImage:(CIImage *)ciImage NS_AVAILABLE_IOS(5_0);- (instancetype)initWithCIImage:(CIImage *)ciImage scale:(CGFloat)scale orientation:(UIImageOrientation)orientation NS_AVAILABLE_IOS(6_0);#endif
image
bundle(cache)
#if __has_include(<UIKit/UITraitCollection.h>)@property (nonatomic, readonly, copy) UITraitCollection *traitCollection NS_AVAILABLE_IOS(8_0); // describes the image in terms of its traits@property (nullable, nonatomic, readonly) UIImageAsset *imageAsset NS_AVAILABLE_IOS(8_0); // The asset is not encoded along with the image. Returns nil if the image is not CGImage based.#endif
Quartz(CGImage)
@property(nullable, nonatomic,readonly) CGImageRef CGImage; // returns underlying CGImageRef or nil if CIImage based- (nullable CGImageRef)CGImage NS_RETURNS_INNER_POINTER CF_RETURNS_NOT_RETAINED;
Core Image(CIImage)
#if __has_include(<CoreImage/CoreImage.h>)@property(nullable,nonatomic,readonly) CIImage *CIImage NS_AVAILABLE_IOS(5_0); // returns underlying CIImage or nil if CGImageRef based#endif
0 0
- cocoa touch——UIImage——create,init
- cocoa touch——UIImage——attribute,draw
- cocoa touch——UILabel
- cocoa touch——UIImageView
- cocoa touch——UISwitch
- cocoa touch——UIProgressView
- cocoa touch——UIActivityIndicatorView
- cocoa touch——UIPageControl
- cocoa touch——UIPickerView
- cocoa touch——NSLayoutAnchor
- cocoa touch——NSLayoutConstraint
- IOS学习之——Cocoa 和Cocoa Touch
- cocoa touch——UIView——frame bounds center
- cocoa touch——UIView——autoresizing
- cocoa touch——UIViewController——生命周期
- cocoa touch——UIScrollView——content view
- cocoa touch——UIView——draw
- cocoa touch——UIView——NSLayoutAnchor
- Tempter of the Bone
- linux下文件操作需要关注的函数
- nginx 配置多域名
- Codeforces Round #287 (Div. 2) C 构造
- java基础----day02:运算符
- cocoa touch——UIImage——create,init
- 腾讯优测优分享干货精选| Android双卡双待适配——隐藏在数据库中的那些秘密
- WebView 与js交互基础总结
- UINib
- linuxfl2440开发板驱动开发之按键驱动
- 二分最大匹配(匈牙利算法+HK算法)
- Error creating bean with name 'menuController': Injection of autowired dependenc
- C# 容量超出了最大容量。 参数名: capacity 错误
- 使用POP3协议接收并解析电子邮件(全)