-
Notifications
You must be signed in to change notification settings - Fork 122
/
Filterbugfix.m
executable file
·75 lines (59 loc) · 2.6 KB
/
Filterbugfix.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
//
// FilterViewController.m
// PictureHandleDemo
//
// Created by AlienJunX on 15/6/3.
// Copyright (c) 2015年 Shanghai Metis IT Co.,Ltd. All rights reserved.
//
#import "FilterViewController.h"
#import "FilteredImageView.h"
@interface FilterViewController ()
@property (strong, nonatomic) FilteredImageView *filteredImageView;
@property (strong, nonatomic) FilteredImageView *filteredImageView1;
@property (strong, nonatomic) CIFilter *filter;
@property (strong, nonatomic) UIImage *inputImage;
@end
@implementation FilterViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.inputImage = [UIImage imageNamed:@"t4"];
//滤镜
self.filter =[CIFilter filterWithName:@"CITwirlDistortion"];
[self.filter setValue:[CIVector vectorWithX:1 Y:180] forKey:kCIInputCenterKey];
[self.filter setValue:@190 forKey:kCIInputRadiusKey];
[self.filter setValue:@(0.01) forKey:kCIInputAngleKey];
self.filteredImageView = [[FilteredImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 144)];
self.filteredImageView.inputImage = self.inputImage;
self.filteredImageView.filter=self.filter;
self.filteredImageView.contentMode = UIViewContentModeScaleAspectFit;
self.filteredImageView.clipsToBounds = NO;
self.filteredImageView.backgroundColor = [UIColor clearColor];
[self.filteredImageView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.view insertSubview:self.filteredImageView atIndex:0];
self.filteredImageView1 = [[FilteredImageView alloc] initWithFrame:CGRectMake(150, 100, 100, 144)];
self.filteredImageView1.inputImage = self.inputImage;
self.filteredImageView1.filter=self.filter;
self.filteredImageView1.contentMode = UIViewContentModeScaleAspectFit;
self.filteredImageView1.clipsToBounds = NO;
self.filteredImageView1.backgroundColor = [UIColor clearColor];
[self.filteredImageView1 setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.view insertSubview:self.filteredImageView1 atIndex:0];
// [self cc:0.1];
NSLog(@"%@",[self.filter valueForKey:kCIInputRadiusKey]);
}
- (IBAction)valueChange:(UISlider *)sender {
// NSLog(@"%@", [self.filter attributes]);
CGFloat f = sender.value -0.5;
[self cc:f];
NSLog(@"%@",NSStringFromCGRect(self.filteredImageView1.frame));
}
- (void) cc:(CGFloat) f{
if(f==0){
f=0.01;
}
[self.filteredImageView.filter setValue:@(f) forKey:kCIInputAngleKey];
[self.filteredImageView setNeedsDisplay];
[self.filteredImageView1.filter setValue:@(f) forKey:kCIInputAngleKey];
[self.filteredImageView1 setNeedsDisplay];
}
@end