UIImage.h

//
//  UIImage.h
//  UIKit
//
//  Copyright (c) 2005-2013, Apple Inc. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <CoreImage/CoreImage.h>
#import <UIKit/UIKitDefines.h>
#import <UIKit/UIColor.h>
#import <UIKit/UIGeometry.h>

typedef NS_ENUM(NSInteger, UIImageOrientation) {
    UIImageOrientationUp,            // 正常视图
    UIImageOrientationDown,          // 旋转180度
    UIImageOrientationLeft,          // 顺时针旋转90度
    UIImageOrientationRight,         // 逆时针旋转90度
    // 镜像相关
    UIImageOrientationUpMirrored,    // 正常视图镜像
    UIImageOrientationDownMirrored,
    UIImageOrientationLeftMirrored,
    UIImageOrientationRightMirrored,
};


typedef NS_ENUM(NSInteger, UIImageResizingMode) {
    UIImageResizingModeTile,            // 瓦片式平铺
    UIImageResizingModeStretch,         // 直接拉伸
};

typedef NS_ENUM(NSInteger, UIImageRenderingMode) {
    UIImageRenderingModeAutomatic,          // Use the default rendering mode for the context where the image is used
    
    UIImageRenderingModeAlwaysOriginal,     // Always draw the original image, without treating it as a template
    UIImageRenderingModeAlwaysTemplate,     // Always draw the image as a template image, ignoring its color information
} NS_ENUM_AVAILABLE_IOS(7_0);

NS_CLASS_AVAILABLE_IOS(2_0) @interface UIImage : NSObject <NSCoding> {
  @package
    CFTypeRef _imageRef;
    CGFloat   _scale;
    struct {
    unsigned int named:1;
    unsigned int imageOrientation:3;
    unsigned int cached:1;
    unsigned int hasPattern:1;
    unsigned int isCIImage:1;
        unsigned int imageSetIdentifer:16;
    unsigned int renderingMode:2;
    } _imageFlags;
}

+ (UIImage *)imageNamed:(NSString *)name;      // 从mainBundle加载图片文件
+ (UIImage *)imageWithContentsOfFile:(NSString *)path;  // 从文件加载
+ (UIImage *)imageWithData:(NSData *)data;  // 从 NSData 对象加载
+ (UIImage *)imageWithData:(NSData *)data scale:(CGFloat)scale NS_AVAILABLE_IOS(6_0);
+ (UIImage *)imageWithCGImage:(CGImageRef)cgImage;  // 从CGImageRef加载
+ (UIImage *)imageWithCGImage:(CGImageRef)cgImage scale:(CGFloat)scale orientation:(UIImageOrientation)orientation NS_AVAILABLE_IOS(4_0);
+ (UIImage *)imageWithCIImage:(CIImage *)ciImage NS_AVAILABLE_IOS(5_0);
+ (UIImage *)imageWithCIImage:(CIImage *)ciImage scale:(CGFloat)scale orientation:(UIImageOrientation)orientation NS_AVAILABLE_IOS(6_0);

- (id)initWithContentsOfFile:(NSString *)path;
- (id)initWithData:(NSData *)data;
- (id)initWithData:(NSData *)data scale:(CGFloat)scale NS_AVAILABLE_IOS(6_0);
- (id)initWithCGImage:(CGImageRef)cgImage;
- (id)initWithCGImage:(CGImageRef)cgImage scale:(CGFloat)scale orientation:(UIImageOrientation)orientation NS_AVAILABLE_IOS(4_0);
- (id)initWithCIImage:(CIImage *)ciImage NS_AVAILABLE_IOS(5_0);
- (id)initWithCIImage:(CIImage *)ciImage scale:(CGFloat)scale orientation:(UIImageOrientation)orientation NS_AVAILABLE_IOS(6_0);

@property(nonatomic,readonly) CGSize             size;
@property(nonatomic,readonly) CGImageRef         CGImage;
- (CGImageRef)CGImage NS_RETURNS_INNER_POINTER;
@property(nonatomic,readonly) CIImage           *CIImage NS_AVAILABLE_IOS(5_0); //
@property(nonatomic,readonly) UIImageOrientation imageOrientation; // 图像旋转
@property(nonatomic,readonly) CGFloat            scale NS_AVAILABLE_IOS(4_0);

// animated images. When set as UIImageView.image, animation will play in an infinite loop until removed. Drawing will render the first image

+ (UIImage *)animatedImageNamed:(NSString *)name duration:(NSTimeInterval)duration NS_AVAILABLE_IOS(5_0);
+ (UIImage *)animatedResizableImageNamed:(NSString *)name capInsets:(UIEdgeInsets)capInsets duration:(NSTimeInterval)duration NS_AVAILABLE_IOS(5_0); // sequence of files
+ (UIImage *)animatedResizableImageNamed:(NSString *)name capInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode duration:(NSTimeInterval)duration NS_AVAILABLE_IOS(6_0);
+ (UIImage *)animatedImageWithImages:(NSArray *)images duration:(NSTimeInterval)duration NS_AVAILABLE_IOS(5_0);

#pragma mark - gif图片中得每一个图片,加上动画时间,可以放到UIImageView的动画数组中进行动画。
@property(nonatomic,readonly) NSArray          *images    NS_AVAILABLE_IOS(5_0);
@property(nonatomic,readonly) NSTimeInterval   duration   NS_AVAILABLE_IOS(5_0);

#pragma - mark drawRect方法中使用的
- (void)drawAtPoint:(CGPoint)point; // 将图片画到某个点,图片的大小是实际的大小
- (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; // 将图片画到一个矩形框里面,图片太小的话,会复制图片充满矩形框

#pragma - mark 按照一定的内缩距离拉伸一张图片,并返回拉伸以后的图片
- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets NS_AVAILABLE_IOS(5_0);
- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode NS_AVAILABLE_IOS(6_0);

@property(nonatomic,readonly) UIEdgeInsets capInsets               NS_AVAILABLE_IOS(5_0);
@property(nonatomic,readonly) UIImageResizingMode resizingMode NS_AVAILABLE_IOS(6_0); // 默认是 UIImageResizingModeTile

- (UIImage *)imageWithAlignmentRectInsets:(UIEdgeInsets)alignmentInsets NS_AVAILABLE_IOS(6_0);
@property(nonatomic,readonly) UIEdgeInsets alignmentRectInsets NS_AVAILABLE_IOS(6_0);

- (UIImage *)imageWithRenderingMode:(UIImageRenderingMode)renderingMode NS_AVAILABLE_IOS(7_0);
@property(nonatomic, readonly) UIImageRenderingMode renderingMode NS_AVAILABLE_IOS(7_0); // 渲染方式

@end

@interface CIImage(UIKitAdditions)

- (id)initWithImage:(UIImage *)image NS_AVAILABLE_IOS(5_0);
- (id)initWithImage:(UIImage *)image options:(NSDictionary *)options NS_AVAILABLE_IOS(5_0);

@end

UIKIT_EXTERN NSData *UIImagePNGRepresentation(UIImage *image);      //  将PNG图片转换成二进制数据
UIKIT_EXTERN NSData *UIImageJPEGRepresentation(UIImage *image, CGFloat compressionQuality);  // 将JPG图片转换成二进制数据


#pragma - mark 失效的方法
@interface UIImage(UIImageDeprecated)

// use resizableImageWithCapInsets: and capInsets.

- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight;
@property(nonatomic,readonly) NSInteger leftCapWidth;   // default is 0. if non-zero, horiz. stretchable. right cap is calculated as width - leftCapWidth - 1
@property(nonatomic,readonly) NSInteger topCapHeight;   // default is 0. if non-zero, vert. stretchable. bottom cap is calculated as height - topCapWidth - 1

@end



最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容