59 // load image from path |
59 // load image from path |
60 UIImage *image = [[UIImage alloc] initWithContentsOfFile: path]; |
60 UIImage *image = [[UIImage alloc] initWithContentsOfFile: path]; |
61 |
61 |
62 if (nil != image) { |
62 if (nil != image) { |
63 // get its CGImage representation with a give size |
63 // get its CGImage representation with a give size |
64 CGImageRef cgImgage = CGImageCreateWithImageInRect([image CGImage], rect); |
64 CGImageRef cgImage = CGImageCreateWithImageInRect([image CGImage], rect); |
65 |
65 |
66 // clean memory |
66 // clean memory |
67 [image release]; |
67 [image release]; |
68 |
68 |
69 // create a UIImage from the CGImage (memory must be allocated already) |
69 // create a UIImage from the CGImage (memory must be allocated already) |
70 UIImage *sprite = [self initWithCGImage:cgImgage]; |
70 UIImage *sprite = [self initWithCGImage:cgImage]; |
71 |
71 |
72 // clean memory |
72 // clean memory |
73 CGImageRelease(cgImgage); |
73 CGImageRelease(cgImage); |
74 |
74 |
75 // return resulting image |
75 // return resulting image |
76 return sprite; |
76 return sprite; |
77 } else { |
77 } else { |
78 DLog(@"error - image == nil"); |
78 DLog(@"error - image == nil"); |
79 return nil; |
79 return nil; |
80 } |
80 } |
|
81 } |
|
82 |
|
83 -(UIImage *)cutAt:(CGRect) rect { |
|
84 CGImageRef cgImage = CGImageCreateWithImageInRect([self CGImage], rect); |
|
85 |
|
86 UIImage *res = [UIImage imageWithCGImage:cgImage]; |
|
87 CGImageRelease(cgImage); |
|
88 |
|
89 return res; |
81 } |
90 } |
82 |
91 |
83 -(UIImage *)convertToGrayScale { |
92 -(UIImage *)convertToGrayScale { |
84 // Create image rectangle with current image width/height |
93 // Create image rectangle with current image width/height |
85 CGRect imageRect = CGRectMake(0, 0, self.size.width, self.size.height); |
94 CGRect imageRect = CGRectMake(0, 0, self.size.width, self.size.height); |