• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Blur NSImage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Blur NSImage


  • Subject: Re: Blur NSImage
  • From: Rob Keniger <email@hidden>
  • Date: Sun, 14 Jun 2009 13:41:12 +1000


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 (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


References: 
 >Blur NSImage (From: Pierce Freeman <email@hidden>)

  • Prev by Date: Re: Blur NSImage
  • Next by Date: Re: Discloser triangle
  • Previous by thread: Re: Blur NSImage
  • Next by thread: Showing a menu in an arbitrary position
  • Index(es):
    • Date
    • Thread