Re: Getting image info without loading entire image
Re: Getting image info without loading entire image
- Subject: Re: Getting image info without loading entire image
- From: Ken Tozier <email@hidden>
- Date: Fri, 19 Jan 2007 19:34:40 -0500
On Jan 19, 2007, at 6:06 PM, Ryan Britton wrote:
Have you looked at CGImageSource?
http://developer.apple.com/documentation/GraphicsImaging/Reference/
CGImageSource/Reference/reference.html
Interesting...
Getting the info through CGImage functions like this
NSURL *url = [NSURL fileURLWithPath: inPath];
CGImageSourceRef srcRef = CGImageSourceCreateWithURL((CFURLRef) url,
NULL);
CGImageRef imgRef = CGImageSourceCreateImageAtIndex(srcRef, 0, NULL);
NSDictionary *imgProps = (NSDictionary *)
CGImageSourceCopyPropertiesAtIndex(srcRef, 0, NULL),
*srcProps = (NSDictionary *) CGImageSourceCopyProperties(srcRef,
NULL);
width = [imgProps objectForKey: @"PixelWidth"];
height = [imgProps objectForKey: @"PixelHeight"];
CFRelease(srcRef);
CFRelease(imgRef);
is *MUCH* faster than getting the same info through NSImageRep like
this.
NSImageRep *img = [NSImageRep imageRepWithContentsOfFile: inPath];
if (img != nil)
{
width = [NSNumber numberWithInt: [img pixelsWide]],
height = [NSNumber numberWithFloat: [img pixelsHigh]];
}
There must be some serious overhead in NSImage classes.
Thanks for the tip Ryan
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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