Reputation: 2188
I want to programatically generate a rectangular image with a solid color fill. How can I do this? I want to populate inputImageView with inputImage.
Here's my code so far, but all I get is an empty image view:
-(void) awakeFromNib{
CIColor *red = [CIColor colorWithRed:1 green:0 blue:0];
CIImage *redImage = [CIImage imageWithColor:red];
NSCIImageRep *ir = [NSCIImageRep imageRepWithCIImage:redImage];
[self setInputImage:[[NSImage alloc] initWithSize: NSMakeSize(25, 25)]];
//magic should be happening right here!
[[self inputImage] addRepresentation:ir];
[[self inputView] setImage:[self inputImage]];
[inputView setNeedsDisplay:YES];
}
Upvotes: 1
Views: 3927
Reputation: 385500
NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(25, 25)];
[image lockFocus];
[[NSColor redColor] setFill];
[NSBezierPath fillRect:NSMakeRect(0, 0, 25, 25)];
[image unlockFocus];
Upvotes: 11