On 14/06/2009, at 1:09 PM, Pierce Freeman wrote:

I will say before hand that I don't really want to dive into Quartz, etc. at the moment and simply want to stick with the "image basics". Anyway, I am making a fullscreen app that has window with a NSImageView that fills the screen. I only say this as it may change how to address this issue (not quite sure about that). Anyway, I am looking to add a quick blur to the
NSImage before I insert it into the NSImageView.  I have not found any
sample code that does this without going into some other framework, and am
wondering if anyone here would have any suggestions.


While it does mean delving into a new API, Core Image is your friend here and it's by far the easiest way to blur an image. It's not very hard. Here's how to get a blurred NSImage from a source NSImage:

NSImage* sourceImage = [NSImage imageNamed:@"YourImage"];
CIImage* inputImage = [CIImage imageWithData:[sourceImage TIFFRepresentation]];
CIFilter* filter = [CIFilter filterWithName:@"CIGaussianBlur"];
[filter setDefaults];
[filter setValue:inputImage forKey:@"inputImage"];
CIImage* outputImage = [filter valueForKey:@"outputImage"];

NSRect outputImageRect = NSRectFromCGRect([outputImage extent]);
NSImage* blurredImage = [[NSImage alloc] initWithSize:outputImageRect.size];
[blurredImage lockFocus];
[outputImage drawAtPoint:NSZeroPoint fromRect:outputImageRect operation:NSCompositeCopy fraction:1.0];
[blurredImage unlockFocus];

Make sure you link against <QuartzCore/QuartzCore.h> and include the QuartzCore framework.

It's more efficient if you create the CIImage directly from a file using -imageWithContentsOfURL: and then draw it using the CIImage - drawAtPoint:fromRect:operation:fraction: method rather than using NSImage objects but if you need to use an NSImageView then you don't have too many options.

--
Rob Keniger



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to