forked from mattgemmell/MGImageUtilities
/
MGImageUtilitiesAppDelegate.m
88 lines (66 loc) · 1.69 KB
/
MGImageUtilitiesAppDelegate.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
84
85
86
87
88
//
// MGImageUtilitiesAppDelegate.m
// MGImageUtilities
//
// Created by Matt Gemmell on 04/07/2010.
// Copyright Instinctive Code 2010.
//
#import "MGImageUtilitiesAppDelegate.h"
#import "UIImage+ProportionalFill.h"
#import "UIImage+Tint.h"
@implementation MGImageUtilitiesAppDelegate
@synthesize window;
@synthesize originalView;
@synthesize resultView;
@synthesize methodControl;
@synthesize tintSwitch;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Load a sample image for the demo.
originalView.image = [UIImage imageNamed:@"original.png"];
[self updateResult];
[window makeKeyAndVisible];
return YES;
}
- (void)dealloc
{
[window release];
[super dealloc];
}
- (IBAction)methodChanged:(id)sender
{
[self updateResult];
}
- (IBAction)tintChanged:(id)sender
{
[self updateResult];
}
- (void)updateResult
{
UIImage *oldImage = originalView.image;
UIImage *newImage;
CGSize newSize = resultView.frame.size;
// Resize the image using the user's chosen method.
switch (methodControl.selectedSegmentIndex) {
case 0:
newImage = [oldImage imageScaledToFitSize:newSize]; // uses MGImageResizeScale
break;
case 1:
newImage = [oldImage imageCroppedToFitSize:newSize]; // uses MGImageResizeCrop
break;
case 2:
newImage = [oldImage imageToFitSize:newSize method:MGImageResizeCropStart];
break;
case 3:
newImage = [oldImage imageToFitSize:newSize method:MGImageResizeCropEnd];
break;
default:
break;
}
// If appropriate, tint the resulting image.
if (tintSwitch.on) {
newImage = [newImage imageTintedWithColor:[UIColor redColor]];
}
resultView.image = newImage;
}
@end