views:

507

answers:

2

Hi, I have written an application in which I want to convert a .jpg image to .bmp format but I it fails with the error:

class_name' may not respond to methd_name".

My code is following :

#import "CalculateRGBViewController.h"

@implementation CalculateRGBViewController

@synthesize skinImage;
@synthesize lblRedColor,btn,img;
struct pixel {
    unsigned char r, g, b,a;
};


-(IBAction)btnClick:(id) sender{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:picker animated:YES];

}
-(void)imagePickerController:(UIImagePickerController *) picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    [picker dismissModalViewControllerAnimated:YES];
    skinImage.  image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

}

+(void)calculateRGB:(UIImage *)skinImage    {

    struct pixel *pixels = (struct pixel *) calloc(1, skinImage.size.width * skinImage.size.height * sizeof(struct pixel));
    if (pixels != nil)
    {
        // Create a new bitmap

        CGContextRef context = CGBitmapContextCreate(
                                                     (void*) pixels,
                                                     skinImage.size.width,
                                                     skinImage.size.height,
                                                     8,
                                                     skinImage.size.width * 4,
                                                     CGImageGetColorSpace(skinImage.CGImage),
                                                     kCGImageAlphaPremultipliedLast
                                                     );
    NSLog( @"Pixel data one red (%i)", context);        
}

}
-(IBAction)btnCalRGB:(id) sender
{
    [self calculateRGB];

}

The shown me following code. 
-(IBAction)btnCalRGB:(id) sender
{
    [self calculateRGB];


}

Warning: CalculateRGBController may not respond to calculateRGB in btnCalRGB button function.

Edit01:

I have also implemented in my code but it again showing same warning.

[self calculateRGB:anUIImage]; 
-(IBAction)btnCalRGB:(id) sender; 

but it again showing same warning. When the button above is pressed, the program throws and exception.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[UIImage skinImage]: unrecognized selector sent to
+1  A: 

You call the method wrong. You must call it like this;

[self calculateRGB:anUIImage];

Your method takes an UIImage as an argument, so you must send it when you call the method. You should also add

+(void)calculateRGB:(UIImage *)skinImage;

to your .h file

Use this

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo { 

instead of this

-(void)imagePickerController:(UIImagePickerController *) picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

and you can write

skinImage.image = image;
EEE
Hi EEE, the following line i also implementing in my code but it again showing same warning.[self calculateRGB:anUIImage];-(IBAction)btnCalRGB:(id) sender on above button the program throwing exception. Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[UIImage skinImage]: unrecognized selector sent to............Thanks
RRB
You call the method like this [self calculateRGB:anUIImage] or like this [self calculateRGB:skinImage.image]? and see the update in my answer.
EEE
EEE, which steps i should have follow for to get number of RGB pixel counting from iphone camera captured image?
RRB
A: 

First of all, to get rid of the error:

+(void)calculateRGB:(UIImage *)skinImage

Should be

- (void)calculateRGB:(UIImage *)skinImage

The + is for class methods, you're about to call this on instances (this is we you need to use the -). So the error is because you try to call the instance method but there is no instance method named calculateRGB:.

The method wants an UIImage to do it's calculation on. This means you should call it (like EEE told you already):

[self calculateRGB:anImage];

anImage would be an UIImage instance you provide. This could be the skinImage that you're already using in the implementation, as shown in your code.

Apart from this, I would recommend not to use an UIViewController subclass for stuff like calculating the RGB values of an image. You should probably use a category of UIImage for this.

bddckr
ChriB, Which class i have to be use instead of UIViewController.
RRB
ChriB, do u have some idea regarding to find out numbers of RGB(red,green,blue) pixels counting from iphone camera captured image or which setps of image processing should i have follow to get those pixels?
RRB