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 Ferry" <email@hidden>
- Date: Fri, 19 Jan 2007 23:05:14 -0800
The CGImageSource functions are intended to be the fastest on the
system, so you won't go wrong with them.
Your original problem, though, was probably that you created your
image with -initWithContentsOfFile:.
The docs for -[NSImage initWithContentsOfFile:] say:
"Unlike initByReferencingFile:, which initializes an NSImage object
lazily, this method immediately opens the specified file and creates
one or more image representations from its data."
The docs for -[NSImage initByReferencingFile:] add,
"This method initializes the image object lazily. It does not actually
open the specified file or create any image representations from its
data until an application attempts to draw the image or request
information about it."
NSImage uses ImageIO (i.e. NSImageSource) for most of its image file reading.
-Ken
On 1/19/07, Ken Tozier <email@hidden> wrote:
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
_______________________________________________
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