-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDMAImageData.m
More file actions
73 lines (61 loc) · 1.68 KB
/
DMAImageData.m
File metadata and controls
73 lines (61 loc) · 1.68 KB
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
//
// DMAImageData.m
// DataManager
//
// Created by Adam Chin on 5/31/15.
// Copyright (c) 2015 Adam Chin. All rights reserved.
//
#import "DMAImageData.h"
@implementation DMAImageData
-(instancetype)init
{
if (self = [super init])
{
}
return self;
}
-(instancetype)initWithImage:(UIImage *)image
{
if (self = [super init])
{
self.imageToTransform = image;
}
return self;
}
-(void)resizeImageByAmount:(float)amount
{
if (self.imageToTransform)
{
CGSize newSize = CGRectMake(0, 0, self.imageToTransform.size.width * amount, self.imageToTransform.size.height * amount).size;
UIGraphicsBeginImageContext(newSize);
[self.imageToTransform drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.imageToTransform = newImage;
}
}
- (NSString *)base64Image
{
if (self.imageToTransform)
{
return [UIImageJPEGRepresentation(self.imageToTransform, 1.0) base64EncodedStringWithOptions:kNilOptions];
}
return nil;
}
- (NSArray *)byteImage
{
if (self.imageToTransform)
{
NSData *imageData = [NSData dataWithData:UIImageJPEGRepresentation(self.imageToTransform, 0.5)];
const unsigned char * bytes = [imageData bytes];
NSUInteger length = [imageData length];
NSMutableArray *byteData = [[NSMutableArray alloc]initWithCapacity:length];
for(int i = 0; i < length; i++)
{
[byteData addObject:[NSNumber numberWithUnsignedChar: bytes[i]]];
}
return byteData;
}
return nil;
}
@end