PDA

View Full Version : Problem in calling utility method




iphonejudy
Apr 21, 2009, 02:53 AM
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
Apr 21, 2009, 02:57 AM
[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
Apr 21, 2009, 03:01 AM
[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
Apr 21, 2009, 03:15 AM
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
Apr 21, 2009, 03:24 AM
//// 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
Apr 21, 2009, 03:41 AM
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
Apr 21, 2009, 03:56 AM
//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






//pictureScreenController.m
#import "pictureScreenController.h"


@implementation pictureScreenController

@synthesize baseImage,colorizeImage,theColor,flag,textfield1,image1,button,textfield2,baseImage1,image1,buton1,b uton2;

+ (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
Apr 21, 2009, 09:55 AM
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
Apr 21, 2009, 10:44 AM
Also, it's common practice to capitalize your class names (e.g. PictureScreenController) to differentiate them from variable names.

mccannmarc
Apr 21, 2009, 02:12 PM
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!!