NSBitmapImageRep/CIImage questions - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: NSBitmapImageRep/CIImage questions (/thread-2427.html)
NSBitmapImageRep/CIImage questions - Caveman - Sep 2, 2008 07:40 PM
Hi I want to begin with some image processing, I want to get an image, apply filters and then accessing pixel data to do some algorithms
1.-I create a CIImage object from a jpg "myCiimage"
2.-I apply some filters
3.-I try to create a NSBitmapImageRep object with
NSBitmapImageRep * myImage = [[NSBitmapImageRep alloc] initWithCIImage:"myCiimage"];
it compiles fine but when I run the application I get the error message "Uncaught exception: <NSInvalidArgumentException> *** -[NSBitmapImageRep initWithCIImage:]: selector not recognized"
here is my code(I'm modifying the CIExposureSample example):
CIContext * context;
CIImage * image;
NSBitmapImageRep * myImage;
CGRect cg = CGRectMake(NSMinX(rect), NSMinY(rect),
context=[[NSGraphicsContext currentContext] CIContext];
image = [CIImage imageWithContentsOfURL: [NSURL fileURLWithPath:
[[NSBundle mainBundle] pathForResource: @"myJPGimage" ofType: @"jpg"]]];
filter1 = [CIFilter filterWithName: @"CIExposureAdjust"
keysAndValues: @"inputImage", image, nil];
[filter1 setValue: [NSNumber numberWithFloat: exposureValue] forKey: @"inputEV"];
image = [filter1 valueForKey: @"outputImage"];
filter2 = [CIFilter filterWithName:@"CIHueAdjust"];
[filter2 setValue: image forKey: @"inputImage"];
[filter2 setValue: [NSNumber numberWithFloat: hueValue] forKey: @"inputAngle"];
image = [filter2 valueForKey: @"outputImage"];
//until here it works fine
myImage = [[NSBitmapImageRep alloc] initWithCIImage:image];
what do you think it can be wrong?
NSBitmapImageRep/CIImage questions - reubert - Sep 2, 2008 08:49 PM
You're not trying to run it on Tiger by any chance are you?
NSBitmapImageRep's initWithCIImage method is 10.5 only. NSCIImageRep's initWithCIImage is available in 10.4, which is why you wouldn't be getting any compile errors.
NSBitmapImageRep/CIImage questions - Caveman - Sep 3, 2008 04:43 PM
Oh crap, yes I'm in tiger
any other solution to this? I want to get pixel data from a CIImage object...
NSBitmapImageRep/CIImage questions - reubert - Sep 3, 2008 04:57 PM
I'm not sure if this is the easiest way, but probably via CIImageRep's (NSImageRep's) drawInRect: method. There are quite a few different ways of capturing that output into various objects, the easiest of which is probably NSImage with something like this (untested):
Otherwise try looking at graphicsContextWithBitmapImageRep: and make that context current and use the same drawInRect function.
Lots of options, none as easy as the one you were trying to use unfortunately.
NSBitmapImageRep/CIImage questions - ThemsAllTook - Sep 4, 2008 05:02 AM
I get pixel data from a CIImage like this. Works on Tiger:
Once you've done that, outputPixels contains the pixel data from the CIImage (outputImage).
NSBitmapImageRep/CIImage questions - Caveman - Sep 6, 2008 01:56 PM
how do I get the BYTES_PER_PIXEL from my jpg image?
also how is the information stored in outputPixels? can I create a NSBitmapImageRep object from outputPixels? to have a method to get the color of the pixel (x,y), a NSColor or something I can work on, or can I get somehow that information from outputPixels directly?
NSBitmapImageRep/CIImage questions - ThemsAllTook - Sep 6, 2008 04:37 PM
Whoops, I forgot to replace BYTES_PER_PIXEL in my paste with its actual value, which is 4. outputPixels ends up as a linear array of bytes representing pixel components (four per pixel, premultiplied), laid out as R, G, B, A, R, G, B, A, ..., so you can just look up color values directly from the array.