UIImage

图片拉伸 - 对背景图片适配时,可能比较有用。

帮助

    NSData *pngData = UIImagePNGRepresentation(image);
    NSData *jpgData = UIImageJPEGRepresentation(image, 0.2);// 压缩
    CIImage *ciImage = [[CIImage alloc] initWithImage:image];
    CGImageRef *imageRef = 。。。

创建

    UIImage *image = [UIImage imageNamed:@"main_fixed_and_float_bg"];
    
    NSString *imagePath = [[NSBundle mainBundle]pathForResource:@"iconfont-nianhua-2" ofType:@"png"];
    UIImage *image2 = [UIImage imageWithContentsOfFile:imagePath];

    UIImage *image3 = [UIImage imageWithData:pngData scale:0.5];

    UIImage *image4 = [UIImage imageWithCIImage:ciImage scale:0.5 orientation:UIImageOrientationDown];

    UIImage *image5 = [UIImage imageWithCGImage:ref scale:0.5 orientation:UIImageOrientationDown];

图片处理

    // 图片拉伸(内部拉伸,平铺)
    UIImage *image4 = [image resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)
                                            resizingMode:UIImageResizingModeStretch];
    
    // 获取新范围内的image
    UIImage *image5 = [image imageWithAlignmentRectInsets:UIEdgeInsetsMake(100, 100, 100, 100)];

    // 渲染图像处理
    UIImage *image7 = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

获取属性

    CGSize imageSize = image.size;
    CGImageRef imageRef = image.CGImage;
    CIImage *imageCIImage = image.CIImage;
    UIImageOrientation orientation = image.imageOrientation;
    CGFloat scale = image.scale;
    // 等等...

绘制图片

- (void)drawAtPoint:(CGPoint)point;                                                        // mode = kCGBlendModeNormal, alpha = 1.0
- (void)drawAtPoint:(CGPoint)point blendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha;
- (void)drawInRect:(CGRect)rect;                                                           // mode = kCGBlendModeNormal, alpha = 1.0
- (void)drawInRect:(CGRect)rect blendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha;

- (void)drawAsPatternInRect:(CGRect)rect; // draws the image as a CGPattern

 

其他

+ (nullable UIImage *)animatedImageNamed:(NSString *)name duration:(NSTimeInterval)duration NS_AVAILABLE_IOS(5_0);  // read sequence of files with suffix starting at 0 or 1
+ (nullable UIImage *)animatedResizableImageNamed:(NSString *)name capInsets:(UIEdgeInsets)capInsets duration:(NSTimeInterval)duration NS_AVAILABLE_IOS(5_0); // sequence of files
+ (nullable UIImage *)animatedResizableImageNamed:(NSString *)name capInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode duration:(NSTimeInterval)duration NS_AVAILABLE_IOS(6_0);
+ (nullable UIImage *)animatedImageWithImages:(NSArray *)images duration:(NSTimeInterval)duration NS_AVAILABLE_IOS(5_0);

@property(nullable, nonatomic,readonly) NSArray *images   NS_AVAILABLE_IOS(5_0); // default is nil for non-animated images
@property(nonatomic,readonly) NSTimeInterval duration NS_AVAILABLE_IOS(5_0); // total duration for all frames. default is 0 for non-animated images

1

你可能感兴趣的:(UIImage)