Re: Creating Gray Scale Image give big leak...
Re: Creating Gray Scale Image give big leak...
- Subject: Re: Creating Gray Scale Image give big leak...
- From: Heinrich Giesen <email@hidden>
- Date: Tue, 18 Dec 2007 18:20:35 +0100
Hi,
On 16.12.2007, at 21:03, Jerry LeVan wrote:
Is there a way to pass an image to a proc that will transform the
image via
core image filters and get a new NSImage back without any leaks?
I do not know why your code leaks, but for me it looks a bit too
complicated.
For creating a gray imageRep I use the following code, which is a
category of NSImageRep
and works without any memory leak (and is fast):
- (NSBitmapImageRep *) grayRepresentation
{
NSSize origSize = [self size];
// create a new representation
NSBitmapImageRep *newRep =
[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:[self pixelsWide]
pixelsHigh:[self pixelsHigh]
bitsPerSample:8
samplesPerPixel:1
hasAlpha:NO // not allowed !
isPlanar:NO
colorSpaceName:NSCalibratedWhiteColorSpace
bytesPerRow:0
bitsPerPixel:0 ];
// this new imagerep has (as default) a resolution of 72 dpi
[NSGraphicsContext saveGraphicsState];
NSGraphicsContext *context = [NSGraphicsContext
graphicsContextWithBitmapImageRep:newRep];
[NSGraphicsContext setCurrentContext:context];
[self drawInRect:NSMakeRect( 0, 0, [newRep pixelsWide], [newRep
pixelsHigh] )];
[NSGraphicsContext restoreGraphicsState];
[newRep setSize:origSize];
return [newRep autorelease];
}
Heinrich
--
Heinrich Giesen
email@hidden
_______________________________________________
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