project_files/HedgewarsMobile/Classes/UIImageExtra.m
changeset 3621 a8ddf681ba7d
parent 3573 c84067629035
child 3697 d5b30d6373fc
equal deleted inserted replaced
3620:c28a86f379f6 3621:a8ddf681ba7d
    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);