0

I have been reading the code that was suggested to me in this thread here: How to get pixel data from a UIImage (Cocoa Touch) or CGImage (Core Graphics)?

I am wondering how I would implement the code in the following manner:

-(IBAction)getRGB:(id)sender {
    // Call getRGBAsFromImage here when pressed. 
}

+ (NSArray*)getRGBAsFromImage:(UIImage*)image atX:(int)xx andY:(int)yy count:(int)count {
   ...
}

Thank you very much.

Edit for 0x90:

-(IBAction)getRGB:(id)sender {    
    UIImage *image = [UIImage imageNamed:@"IMG_0121.JPG"];
    [self getRGBAsFromImage:image atX:40 andY:40 count:40];
}
Community
  • 1
  • 1
tguidon
  • 139
  • 2
  • 10
  • um, add `+ (NSArray*)getRGBAsFromImage:(UIImage*)image atX:(int)xx andY:(int)yy count:(int)count;` to your header file and call `[self getRGBAsFromImage:image atX:xx andY:yy count:count];` from getRGB?? – null0pointer Feb 21 '12 at 03:40
  • This also fixed the previous error. Now I can't seem to properly load the image variable – tguidon Feb 21 '12 at 04:32

1 Answers1

1

You would define a strong/retained (depends on whether you use ARC) property to store the returned NSArray and then call the method as such:

-(IBAction)getRGB:(id)sender {
    propertyYouDefined = [self getRGBAsFromImage:image atX:42 andY:42 count:42];
}
0x90
  • 6,079
  • 2
  • 36
  • 55
  • Thank you for the response. That resolved the error with not being able to call the function. Do you have any advice on how to load the 'image' aspect? I have a JPG in my resources folder I would like to use. – tguidon Feb 21 '12 at 04:31
  • In my IBAction I am attempting this: NSString * path = [[NSBundle mainBundle] pathForResource:@"IMG_0121" ofType:@"JPG"]; UIImage * image = [[UIImage alloc]initWithContentsOfFile:path]; – tguidon Feb 21 '12 at 04:32
  • While there are many ways to load images, the easiest way to load an image is: UIImage *image = [UIImage imageNamed:@"IMG_0121.JPG"]; – 0x90 Feb 21 '12 at 05:06
  • Hmm I tried that (please view edited post). Should it be placed in the IBActon or the NSArray? – tguidon Feb 21 '12 at 05:20