Problem in calling utility method

Discussion in 'iOS Programming' started by iphonejudy, Apr 21, 2009.

  1. macrumors 6502

    iphonejudy

    Joined:
    Sep 12, 2008
    #1
    Hi,


    I want to call the below method

    (UIImage *)colorizeImage:(UIImage *)baseImage1 color:(UIColor *)theColor
    {

    }

    So i used,

    [self colorizeImage:baseImage1 :theColor];


    But i got the error

    *** -[pictureScreenController colorizeImage:]: unrecognized selector sent to instance 0x4673d0

    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[pictureScreenController colorizeImage:]: unrecognized selector sent to instance 0x4673d0'
     
  2. macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK
    #2
    Code:
    [self colorizeImage:baseImage1 color:theColor];
    I cant even be bothered explaining to you why your first one didn't work (take some time to actually learn Objective-C and you will soon see why) but the above will work so long as baseImage1 is a valid UIImage and theColor is a valid UIColor.
     
  3. thread starter macrumors 6502

    iphonejudy

    Joined:
    Sep 12, 2008
    #3
    I got below error when i used the code given by you
    [self colorizeImage:baseImage1 color:theColor];


    -[pictureScreenController colorizeImage:color:]: unrecognized selector sent to instance 0x4673d0

    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:

    '*** -[pictureScreenController colorizeImage:color:]: unrecognized selector sent to instance 0x4673d0'

    2009-04-21 13:31:15.639 Testapp[1940:20b] Stack: (
    2492104971,
    2425527867,
    2492134154,
    2492127500,
    2492127698,
    11993,
    816728470,
    816728470,
    816274271,
    816209415,
    816206378,
    829003042,
    829012108,
    2491606517,
    2491608280,
    829005112,
    829005309,
    816175835,
    816221412,
    9176,
    9030
    )
     
  4. macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK
    #4
    In that case the problem is beyond the code that you have provided and we will have to see more of your code to diagnose it. You were calling the method wrong either way though.

    Is the colorizeImage:color: method actually part of your pictureScreenController or have you implemented it elsewhere?
     
  5. thread starter macrumors 6502

    iphonejudy

    Joined:
    Sep 12, 2008
    #5
    //// pictureScreenController.m

    + (UIImage *)colorizeImage:(UIImage *)baseImage1 color:(UIColor *)theColor {

    NSLog(@"I am colorizeImage");
    UIGraphicsBeginImageContext(baseImage1.size);

    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGRect area = CGRectMake(0, 0, baseImage1.size.width, baseImage1.size.height);

    CGContextScaleCTM(ctx, 1, -1);
    CGContextTranslateCTM(ctx, 0, -area.size.height);

    CGContextSaveGState(ctx);
    CGContextClipToMask(ctx, area, baseImage1.CGImage);

    [theColor set];
    CGContextFillRect(ctx, area);

    CGContextRestoreGState(ctx);

    CGContextSetBlendMode(ctx, kCGBlendModeMultiply);

    CGContextDrawImage(ctx, area, baseImage1.CGImage);

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return newImage;
    }

    //Touch
    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
    UIColor *redColor;

    [self colorizeImage:baseimage1 color:theColor];

    }
     
  6. macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK
    #6
    can you post the header file too? and start wrapping your code in the code brackets please, your code is depressing me with all the sad faces :p
     
  7. thread starter macrumors 6502

    iphonejudy

    Joined:
    Sep 12, 2008
    #7
    Code:
    
    //pictureScreenController.h
    #import <UIKit/UIKit.h>
    
    @interface pictureScreenController : UIViewController {
    
    	IBOutlet UIImageView *baseImage,*colorizeImage,*baseImage1,*image1;
    	IBOutlet UIColor *theColor; 
    	Boolean *flag;
    	IBOutlet UITextField *textfield1;
    	IBOutlet UITextField *textfield2;
    	IBOutlet UIButton *buton1;
    	IBOutlet UIButton *buton2;
    	NSString *button;
    	CGColorRef bgColor;
    	CGColorRef coloredPatternColor;
    }
    
    @property(nonatomic ,retain) UIImageView *baseImage;
    @property(nonatomic ,retain) UIImageView *baseImage1;
    @property(nonatomic ,retain) UIImageView *image1;
    @property(nonatomic ,retain) UIImageView *colorizeImage;
    @property(nonatomic ,retain) UIColor *theColor; 
    @property(nonatomic ,retain) UITextField *textfield1;
    @property(nonatomic ,retain) UITextField *textfield2;
    @property(nonatomic ,retain) UIButton *buton1;
    @property(nonatomic ,retain) UIButton *buton2;
    @property(nonatomic ,assign) Boolean *flag;
    //@property(nonatomic ,retain) UIImage *image1;
    @property(nonatomic ,retain) NSString *button;
    - (IBAction) displayColors:(id)sender;
    - (IBAction) displayColors1:(id)sender;
    
    @end
    
    
    

    Code:
    //pictureScreenController.m
    #import "pictureScreenController.h"
    
    
    @implementation pictureScreenController
    
    @synthesize baseImage,colorizeImage,theColor,flag,textfield1,image1,button,textfield2,baseImage1,image1,buton1,buton2;
    
     + (UIImage *)colorizeImage:(UIImage *)baseImages color:(UIColor *)theColor {
    	
    	NSLog(@"I am colorizeImage");
        UIGraphicsBeginImageContext(baseImages.size);
        
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        CGRect area = CGRectMake(0, 0, baseImages.size.width, baseImages.size.height);
        
        CGContextScaleCTM(ctx, 1, -1);
        CGContextTranslateCTM(ctx, 0, -area.size.height);
        
        CGContextSaveGState(ctx);
        CGContextClipToMask(ctx, area, baseImages.CGImage);
        
        [theColor set];
        CGContextFillRect(ctx, area);
    	
        CGContextRestoreGState(ctx);
        
        CGContextSetBlendMode(ctx, kCGBlendModeMultiply);
        
        CGContextDrawImage(ctx, area, baseImages.CGImage);
    	
        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
        
        UIGraphicsEndImageContext();
        
        return newImage;
    }
    
    
    
    
    
    //Color the image
    
    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
    {        UIColor *redColor;
    	UIImage *colorizeImage1;
    	UIColor *theColor;
          image1=baseImage1.image;
    	NSLog(@"I am touch");
    	//[self colorizeImage1:image1 color:redColor];	//UIColor *redColor;
    
    	
    
     
  8. macrumors regular

    Joined:
    Apr 9, 2009
    #8
    pretty obvious. PLEASE go learn objective-c before you start coding for the iphone, please please please, or else you'll have questions like this over and over.

    you declared colorizeImage:color: with a +, which makes it a static method. the correct call for a static method would be
    [pictureScreenController colorizeImage:something color:somethingElse];

    but I guess you wanted to declare it an instance method, which is declared by a -
    but all this help isn't actually more than I fixing your code without you understanding why. please read a little about objective-c, google will give you excellent tutorials!
     
  9. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #9
    Also, it's common practice to capitalize your class names (e.g. PictureScreenController) to differentiate them from variable names.
     
  10. macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK
    #10
    That is exactly why I didn't even bother answering her after she posted the code, the longer we keep feeding her answers to everything the more she is going to ask them. And to the OP, if you can't frigging program then don't tell people you can and definately DON'T ACCEPT CONTRACTS!!
     

Share This Page