Re: 2nd Try: Access raw pixel data of a CIImage?
Re: 2nd Try: Access raw pixel data of a CIImage?
- Subject: Re: 2nd Try: Access raw pixel data of a CIImage?
- From: "Adam R. Maxwell" <email@hidden>
- Date: Sat, 7 Jul 2007 11:48:37 -0700
On Jul 7, 2007, at 10:14, Simon Raisin wrote:
I've heard that there are 3rd party frameworks that can do this, but
there
has to be a built-in, supported method.
I realize that CIImage isn't really an "image", more of a recipe for
how to
draw an image. Thus, couldn't I draw the image to an off-screen
buffer and
then read the data from there?
There are various ways to do it (some of which leak memory, so be
careful). Here's what I use in an NSAnimation subclass:
// filter is a CIFilter ivar, bitmapData is a CFDataRef ivar
CIImage *image = [filter valueForKey:@"outputImage"];
CGRect rect = [image extent];
CGImageRef cgImage = [[[NSGraphicsContext currentContext]
CIContext] createCGImage:image fromRect:rect];
CFDataSetLength(bitmapData, 0);
CGImageDestinationRef imDest =
CGImageDestinationCreateWithData(bitmapData, kUTTypeTIFF, 1, NULL);
CGImageDestinationAddImage(imDest, cgImage, NULL);
CGImageDestinationFinalize(imDest);
CFRelease(imDest);
CGImageRelease(cgImage);
NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc]
initWithData:(NSData *)bitmapData];
This gives you an NSBitmapImageRep instance, so you can do whatever
you want with the pixel data at that point. Erik Buck's method looks
more interesting, though.
--
Adam
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden