Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

iphonejudy

macrumors 6502
Original poster
Sep 12, 2008
301
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'
 

mccannmarc

macrumors 6502
Aug 15, 2008
270
0
Manchester, UK
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.
 

iphonejudy

macrumors 6502
Original poster
Sep 12, 2008
301
1
Code:
[self colorizeImage:baseImage1 color:theColor];

I cant even be bothered explaining to you why your first one didn't work (learn how to program objective c properly before starting projects 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.

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
)
 

mccannmarc

macrumors 6502
Aug 15, 2008
270
0
Manchester, UK
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?
 

iphonejudy

macrumors 6502
Original poster
Sep 12, 2008
301
1
//// 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];

}
 

mccannmarc

macrumors 6502
Aug 15, 2008
270
0
Manchester, UK
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
 

iphonejudy

macrumors 6502
Original poster
Sep 12, 2008
301
1
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;
 

BlackWolf

macrumors regular
Apr 9, 2009
244
0
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!
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
Also, it's common practice to capitalize your class names (e.g. PictureScreenController) to differentiate them from variable names.
 

mccannmarc

macrumors 6502
Aug 15, 2008
270
0
Manchester, UK
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!

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!!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.