forked from Adrian2112/UIImage-BlurredFrame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIImage+BlurredFrame.m
83 lines (65 loc) · 2.75 KB
/
UIImage+BlurredFrame.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// UIImage+blurredFrame.m
//
// Created by Adrian Gzz on 04/11/13.
// Copyright (c) 2013 Icalia Labs. All rights reserved.
//
#import "UIImage+BlurredFrame.h"
#import "UIImage+ImageEffects.h"
@implementation UIImage (BlurredFrame)
-(UIImage *)croppedImageAtFrame:(CGRect)frame
{
frame = CGRectMake(frame.origin.x * self.scale, frame.origin.y * self.scale, frame.size.width * self.scale, frame.size.height * self.scale);
CGImageRef sourceImageRef = [self CGImage];
CGImageRef newImageRef = CGImageCreateWithImageInRect(sourceImageRef, frame);
UIImage *newImage = [UIImage imageWithCGImage:newImageRef scale:[self scale] orientation:[self imageOrientation]];
CGImageRelease(newImageRef);
return newImage;
}
#pragma mark - Marge two Images
- (UIImage *) addImageToImage:(UIImage *)img atRect:(CGRect)cropRect{
CGSize size = CGSizeMake(self.size.width, self.size.height);
UIGraphicsBeginImageContext(size);
CGPoint pointImg1 = CGPointMake(0,0);
[self drawAtPoint:pointImg1];
CGPoint pointImg2 = cropRect.origin;
[img drawAtPoint: pointImg2];
UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}
- (UIImage *)applyLightBluredAtFrame:(CGRect)frame
{
UIImage *bluredFrame = [[self croppedImageAtFrame:frame] applyLightEffect];
return [self addImageToImage:bluredFrame atRect:frame];
}
- (UIImage *)applyLightEffectAtFrame:(CGRect)frame
{
UIImage *blurredFrame = [[self croppedImageAtFrame:frame] applyLightEffect];
return [self addImageToImage:blurredFrame atRect:frame];
}
- (UIImage *)applyExtraLightEffectAtFrame:(CGRect)frame
{
UIImage *blurredFrame = [[self croppedImageAtFrame:frame] applyExtraLightEffect];
return [self addImageToImage:blurredFrame atRect:frame];
}
- (UIImage *)applyDarkEffectAtFrame:(CGRect)frame
{
UIImage *blurredFrame = [[self croppedImageAtFrame:frame] applyDarkEffect];
return [self addImageToImage:blurredFrame atRect:frame];
}
- (UIImage *)applyTintEffectWithColor:(UIColor *)tintColor atFrame:(CGRect)frame
{
UIImage *blurredFrame = [[self croppedImageAtFrame:frame] applyTintEffectWithColor:tintColor];
return [self addImageToImage:blurredFrame atRect:frame];
}
- (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius
tintColor:(UIColor *)tintColor
saturationDeltaFactor:(CGFloat)saturationDeltaFactor
maskImage:(UIImage *)maskImage
atFrame:(CGRect)frame
{
UIImage *blurredFrame = [[self croppedImageAtFrame:frame] applyBlurWithRadius:blurRadius tintColor:tintColor saturationDeltaFactor:saturationDeltaFactor maskImage:maskImage];
return [self addImageToImage:blurredFrame atRect:frame];
}
@end