博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UIImage常用属性和方法
阅读量:2339 次
发布时间:2019-05-10

本文共 4349 字,大约阅读时间需要 14 分钟。

一、属性

1size: reflects orientation setting. In iOS 4.0 and later, this is measured in points. In 3.x and earlier, measured in pixels。设置控件的尺寸。

@property(nonatomic,readonly) CGSize size;

2CGImage: returns underlying CGImageRef or nil if CIImage based.底层的 Quartz图像数据(只读),如果图像数据已经在内存中被清除,强行调用这个方法,可以加载回内存中的数据。加载图像数据可能会带来对性能的影响。如果 UIImage对象使用 CIImage 对象进行初始化,该属性的值是空。

@property(nullable, nonatomic,readonly) CGImageRef CGImage;

3scale:图像缩放比例。

@property(nonatomic,readonly) CGFloat scale;

4images: default is nil for non-animated images。默认没有动画图像。动画图像组。这是一个图片数组,可以通过这个属性播放动画。

@property(nullable, nonatomic,readonly) NSArray<UIImage *> *images;

5duration: total duration for all frames. default is 0 for non-animated images。播放动画的时间。

@property(nonatomic,readonly) NSTimeInterval duration;

6capInsets: The end-cap insets. (read-only)指定图片拉伸时哪个范围内的图片可以被平铺或拉伸。

@property(nonatomic,readonly) UIEdgeInsets capInsets               NS_AVAILABLE_IOS(5_0);

7resizingMode: The resizing mode of the image. (read-only)枚举值,图片缩放模式

@property(nonatomic,readonly) UIImageResizingMode resizingMode NS_AVAILABLE_IOS(6_0);

8alignmentRectInsets:布局图像位置的对齐参数(只读)

@property(nonatomic,readonly) UIEdgeInsets alignmentRectInsets NS_AVAILABLE_IOS(6_0);

9renderingMode:图片的呈现方式(只读)

@property(nonatomic, readonly) UIImageRenderingMode renderingMode NS_AVAILABLE_IOS(7_0);

10traitCollection:描述对象的特征集合(只读)

@property (nonatomic, readonly, copy) UITraitCollection *traitCollection NS_AVAILABLE_IOS(8_0);

11imageAsset:返回一个参考image asset相关联的图片。(只读)如果你从参考文件创建的图片,数据,CGImageRef或者如果图片是动画,然后imageAsset的值将是 nil。基于CIImage的图片将总是返回 nil

@property (nullable, nonatomic, readonly) UIImageAsset *imageAsset NS_AVAILABLE_IOS(8_0);

12flipsForRightToLeftLayoutDirection:一个布尔值,该值指示图像是否应该从右侧向左侧布局(只读)

@property (nonatomic, readonly) BOOL flipsForRightToLeftLayoutDirection NS_AVAILABLE_IOS(9_0);

二、常用方法

1imageNamed:load from main bundle。类方法,从main bundle加载图片。

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

2imageWithContentsOfFile:类方法,从文件加载图片内容。

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

3imageWithData:类方法,从数据加载图片内容。

+ (nullable UIImage *)imageWithData: (NSData *)data;

4imageWithCGImage:类方法,加载 CGImageRef图片

+ (UIImage *)imageWithCGImage: (CGImageRef)cgImage;

5initWithContentsOfFile:对象方法,从文件加载图片

- (nullable instancetype)initWithContentsOfFile: (NSString *)path;

6initWithData:对象方法,从数据加载图片

- (nullable instancetype)initWithData: (NSData *)data;

7imageWithCGImage::对象方法,加载 CGImageRef图片

- (UIImage *)imageWithCGImage: (CGImageRef)cgImage;

8CGImage: CGImage get方法,详情请见上面CGImage属性解释。

- (nullable CGImageRef)CGImage;

9animatedImageNamed: duration:: read sequence of files with suffix starting at 0 or 1。从01开始读取带有后缀的文件序列。创建并返回一个动画图像。

+ (nullable UIImage *)animatedImageNamed: (NSString *)name duration: (NSTimeInterval)duration;

10animatedImageNamed: duration:从一组现有的图像,创建并返回一个动画图像。

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

下面这些方法是关于绘图的:

1drawAtPoint:: mode = kCGBlendModeNormal, alpha = 1.0。在 Point这个点绘图。

- (void)drawAtPoint: (CGPoint)point;

2drawAtPoint:blendMode: alpha::在 Point这个点,以某种模式绘图。

- (void)drawAtPoint: (CGPoint)point blendMode: (CGBlendMode)blendMode alpha: (CGFloat)alpha;

3drawInRect:mode = kCGBlendModeNormal, alpha = 1.0。在某个具体位置进行绘图。

- (void)drawInRect: (CGRect)rect;

4drawInRect: blendMode:alpha::在某个具体位置,以某种模式,某种透明度进行绘图。

- (void)drawInRect: (CGRect)rect blendMode: (CGBlendMode)blendMode alpha: (CGFloat)alpha;

5drawAsPatternInRect:draws the image as a CGPattern.在某个具体位置平铺图像。

- (void)drawAsPatternInRect: (CGRect)rect;

6resizableImageWithCapInsets::创建并返回一个指定边距的图像对象。

- (UIImage *)resizableImageWithCapInsets: (UIEdgeInsets)capInsets;

7resizableImageWithCapInsets:resizingMode:创建并返回一个指定边距和伸缩模式的图片对象。

- (UIImage *)resizableImageWithCapInsets: (UIEdgeInsets)capInsets resizingMode: (UIImageResizingMode)resizingMode NS_AVAILABLE_IOS(6_0);

8imageWithAlignmentRectInsets::返回一个指定了对齐方式的图片,一个新的图片对象。

- (UIImage *)imageWithAlignmentRectInsets: (UIEdgeInsets)alignmentInsets NS_AVAILABLE_IOS(6_0);

9imageWithRenderingMode::根据渲染模式,创建一并返回一个新的图片对象

- (UIImage *)imageWithRenderingMode: (UIImageRenderingMode)renderingMode NS_AVAILABLE_IOS(7_0);

10imageFlippedForRightToLeftLayoutDirection::返回当前图片,准备水平旋转时,它会从右向左布局。

- (UIImage *)imageFlippedForRightToLeftLayoutDirection NS_AVAILABLE_IOS(9_0);

转载地址:http://bcwvb.baihongyu.com/

你可能感兴趣的文章
SRS源码分析-协程相关类
查看>>
为何我看好社群直播
查看>>
为何我看好电商直播
查看>>
为何我看好老幼监控直播市场
查看>>
我为什么看好在线视频行业
查看>>
Xeon E3-1500 v5 GPU
查看>>
skylake AVC性能
查看>>
RTSP 协议分析 (一)
查看>>
RTSP协议分析(二)
查看>>
IPTV的前世今生与发展
查看>>
x264中的汇编x86inc.asm
查看>>
X264中的sad-a.asm
查看>>
x264中的cpu-a.asm
查看>>
x264中的DCT变换 dct-a.asm
查看>>
X264的时耗分析
查看>>
H.264 Profile、Level、Encoder三张简图
查看>>
NEON指令集综述
查看>>
FFmpeg的H.264解码器源代码简单分析:概述
查看>>
linux下编译调试x264
查看>>
debug和release版本的区别
查看>>