+ (UIImage *)imageNamed:(NSString *)name
inBundle:(NSBundle *)bundle
compatibleWithTraitCollection:(UITraitCollection *)traitCollection

  name:图片的名字。bundle:设置为nil则默认为main bundle。traitCollection:设置为nil则为main screen中描述的traits。

  该方法在系统的缓存中查找具有指定名字和特征集的图像并返回。如果在缓存中没有找到,该方法将定位到disk和asset catalog查找图像。如果没有合适的图像,将返回nil。

+ (UIImage *)imageNamed:(NSString *)name

  如果屏幕的scale为2.0,该方法首先搜索带@2x后缀的文件名。如,name = @“button",会先搜索button@2x的文件。


创建新的图像对象

+ (UIImage *)imageWithContentsOfFile:(NSString *)path

  path参数可为绝对路径或者相对路径。该方法不会缓存图像对象。

+ (UIImage *)imageWithData:(NSData *)data
+ (UIImage *)imageWithData:(NSData *)data
scale:(CGFloat)scale

  如果scale = 1.0,将使得图像的大小跟基于像素的图像大小相匹配。如果scale = 2.0,图像的大小将会改变。

+ (UIImage *)imageWithCGImage:(CGImageRef)cgImage  
+ (UIImage *)imageWithCGImage:(CGImageRef)imageRef
scale:(CGFloat)scale
orientation:(UIImageOrientation)orientation

  orientation指定图像的方向。

+ (UIImage *)imageWithCIImage:(CIImage *)ciImage
+ (UIImage *)imageWithCIImage:(CIImage *)ciImage
scale:(CGFloat)scale
orientation:(UIImageOrientation)orientation
- (UIImage *)imageWithAlignmentRectInsets:(UIEdgeInsets)alignmentInsets
+ (UIImage *)animatedImageNamed:(NSString *)name
duration:(NSTimeInterval)duration

  name:绝对路径或相对路径,无后缀。

+ (UIImage *)animatedImageWithImages:(NSArray<UIImage *> *)images
duration:(NSTimeInterval)duration

  images:UIImage对象组成的数组,全部的图像应当具有相同的size和scale。

+ (UIImage *)animatedResizableImageNamed:(NSString *)name
capInsets:(UIEdgeInsets)capInsets
duration:(NSTimeInterval)duration

  如果name = @"image",这个方法会尝试去加载文件名为image0,image1, ... , image1024的图像。全部图像应具有相同的size和scale。

- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets
+ (UIImage *)animatedResizableImageNamed:(NSString *)name
capInsets:(UIEdgeInsets)capInsets
resizingMode:(UIImageResizingMode)resizingMode
duration:(NSTimeInterval)duration
- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets
resizingMode:(UIImageResizingMode)resizingMode

  图像的resizingMode 默认为UIImageResizingModeTile。当想要使用UIImageResizingModeStretch时,才调用该方法。

- (UIImage *)imageWithRenderingMode:(UIImageRenderingMode)renderingMode
- (UIImage *)imageFlippedForRightToLeftLayoutDirection

  水平翻转图像。


初始化UIImage对象:

- (instancetype)initWithContentsOfFile:(NSString *)path

  path:文件的路径,应包含扩展名。

  该方法将图像加载入内存并标记为purgeable。如果需要加载图像数据时但已被清除,图像对象会再次从指定的路径加载数据。

- (instancetype)initWithData:(NSData *)data
- (instancetype)initWithData:(NSData *)data
scale:(CGFloat)scale
- (instancetype)initWithCGImage:(CGImageRef)CGImage
- (instancetype)initWithCGImage:(CGImageRef)imageRef
scale:(CGFloat)scale
orientation:(UIImageOrientation)orientation
- (instancetype)initWithCIImage:(CIImage *)ciImage
- (instancetype)initWithCIImage:(CIImage *)ciImage
scale:(CGFloat)scale
orientation:(UIImageOrientation)orientation

图像对象的属性:

@property(nonatomic, readonly) UIImageOrientation imageOrientation

typedef enum {

UIImageOrientationUp,

UIImageOrientationDown ,   // 180 deg rotation

UIImageOrientationLeft ,   // 90 deg CW

UIImageOrientationRight ,   // 90 deg CCW

UIImageOrientationUpMirrored ,    // as above but image mirrored along

// other axis. horizontal flip

UIImageOrientationDownMirrored ,  // horizontal flip

UIImageOrientationLeftMirrored ,  // vertical flip

UIImageOrientationRightMirrored , // vertical flip

} UIImageOrientation;

@property(nonatomic, readonly) CGSize size

  size反应了图像以point测量的逻辑大小。

@property(nonatomic, readonly) CGFloat scale

  如果加载的图像文件名包括@2x,scale则为2.0。其他图像都假设其scale为1.0。

  size * scale 可获得图像的像素大小。

@property(nonatomic, readonly) BOOL flipsForRightToLeftLayoutDirection
@property(nonatomic, readonly) UIImageResizingMode resizingMode

typedef enum {

UIImageResizingModeTile,

UIImageResizingModeStretch,

} UIImageResizingMode;

@property(nonatomic, readonly) CGImageRef CGImage
@property(nonatomic, readonly) CIImage *CIImage
@property(nonatomic, readonly) NSArray <UIImage *> *images

  对于non-animated图像,images的值为nil。

@property(nonatomic, readonly) NSTimeInterval duration

  对于non-animated图像,duration的值为0.0。

@property(nonatomic, readonly) UIEdgeInsets capInsets
@property(nonatomic, readonly) UIEdgeInsets alignmentRectInsets
@property(nonatomic, readonly) UIImageAsset *imageAsset
@property(nonatomic, readonly, copy) UITraitCollection *traitCollection
@property(nonatomic, readonly) UIImageRenderingMode renderingMode

typedef enum : NSInteger {

UIImageRenderingModeAutomatic,

UIImageRenderingModeAlwaysOriginal,

UIImageRenderingModeAlwaysTemplate,

information

} UIImageRenderingMode;


绘制图像:

- (void)drawAtPoint:(CGPoint)point

  point:图像的左上角。

  该方法绘制的图像完全不透明,并使用kCGBlendModeNormal 混合模式。

- (void)drawAtPoint:(CGPoint)point
blendMode:(CGBlendMode)blendMode
alpha:(CGFloat)alpha
- (void)drawInRect:(CGRect)rect
- (void)drawInRect:(CGRect)rect
blendMode:(CGBlendMode)blendMode
alpha:(CGFloat)alpha
- (void)drawAsPatternInRect:(CGRect)rect

UIImage 类说明的更多相关文章

  1. UIImage类扩展返回一个带边框的圆形图片

    /** * 将image转换为圆型带边框的图片(最好写一个UIImage的类扩展) * * @param name 图片的名字 * @param borderWidth 外层边框的宽度 * @para ...

  2. 关于UIImage类的对象两种初始化方法的区别

    1.imageNamed: UIImage *image = [UIImage imageNamed:"]; UIImage的类方法 第一次读取图片的时候,先把这个图片放到缓存中,下次再使用 ...

  3. 聊天气泡 button backgroundImage uiimage 拉伸 stretchableImageWithLeftCapWidth: 方法的使用

    - (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCap ...

  4. UIImage学习

    UIImage A UIImage object is a high-level way to display image data. You can create images from files ...

  5. UIImage 相关操作

    修改UIImage大小 修改UISlider的最大值和最小值图片的时候,发现需要修改图片的大小,否则会导致UISlider变形.目前苹果还不支持直接修改UIImage类的大小,只能修改UIImageV ...

  6. [转] UIImage 图像-IOS开发 (实例)

    转自  http://justcoding.iteye.com/blog/1470931 一 UIImageView 简介 UIImageView是显示图片的控件,显示图片时,首先需要把图片加载到UI ...

  7. Swift - 使用CGBlendMode改变UIImage颜色

    类似于PS,Swift中也可对图片UIImage进行图层混合(blending),而且提供了相当丰富的混合模式(blendMode).本文先介绍使用其中的kCGBlendModeDestination ...

  8. UIImage扩展用代码直接改变图片大小

    以下内容属于转载 在iOS中,uiimage没有用于修改大小的属性,要在代码中改变uiimage图片的大小,需要扩展UIImage类,如下: 头文件: #import<UIKit/UIKit.h ...

  9. IOS 修改UIImage大小

    在iOS中,uiimage没有用于修改大小的属性,要在代码中改变uiimage图片的大小,需要扩展UIImage类,如下: 头文件: #import<UIKit/UIKit.h> @int ...

随机推荐

  1. 【redis专题(7)】命令语法介绍之Pub/Sub

    Redis 发布订阅(pub/sub)是一种消息通信模式:发送者(pub)发送消息,订阅者(sub)接收消息.主要的目的是解耦消息发布者和消息订阅者之间的耦合,这点和设计模式中的观察者模式比较相似.p ...

  2. 通过Socket让远程电脑执行脚本

    实现功能: 客户端发送命令,服务器接收命令并执行 服务端: import socketserver, os class MyTCPHandler(socketserver.BaseRequestHan ...

  3. DNS区域传送漏洞实验以及二级域名爆破

    DNS区域传送漏洞实验以及二级域名爆破 目录: 1.DNS服务器的域传送漏洞(nslookup交互式.非交互式.批处理三种方式) 2.写个二级域名爆破脚本 一.DNS服务器的域传送漏洞 实验环境: 服 ...

  4. 关于java中assert(断言)的使用讲解

    说明:写的不是很全面,有任何问题请留言,多交流,谢谢! 1.eclipse.myeclipse开启assert(断言),默认是关闭,如下: 说白了就是设置一下jvm的参数,参数是-ea或者-enabl ...

  5. Java中使用elasticsearch搜索引擎实现简单查询、修改等操作-已在项目中实际应用

    以下的操作环境为:jdk:1.8:elasticsearch:5.2.0 maven架包下载坐标为: <dependency> <groupId>org.elasticsear ...

  6. npm 安装卸载模块

    npm安装模块 npm install xxx利用 npm 安装xxx模块到当前命令行所在目录 npm install -g xxx利用npm安装全局模块xxx 1 2 本地安装时将模块写入packa ...

  7. node.js—File System(文件系统模块)

    文件系统模块概述 该模块是核心模块,提供了操作文件的一些API,需要使用require导入后使用,通过 require('fs') 使用该模块 文件 I/O 是由简单封装的标准 POSIX 函数提供的 ...

  8. BZOJ 4820 [SDOI2017] 硬币游戏

    Description 周末同学们非常无聊,有人提议,咱们扔硬币玩吧,谁扔的硬币正面次数多谁胜利.大家纷纷觉得这个游戏非常符合同学们的特色,但只是扔硬币实在是太单调了.同学们觉得要加强趣味性,所以要找 ...

  9. UVA1471-Copying Books(二分答案)

    Problem UVA1471-Copying Books Accept: 2669  Submit: 22797Time Limit: 3000 mSec Problem Description B ...

  10. 深度学习之GRU网络

    1.GRU概述 GRU是LSTM网络的一种效果很好的变体,它较LSTM网络的结构更加简单,而且效果也很好,因此也是当前非常流形的一种网络.GRU既然是LSTM的变体,因此也是可以解决RNN网络中的长依 ...