NSImage size?
NSImage size?
- Subject: NSImage size?
- From: Bret Kurth <email@hidden>
- Date: Mon, 23 May 2005 15:59:29 -0500
I am writing an image layout type of application that, upon opening files, requires the width and height in pixels of images as stored on disk. The following code snippet gives me that information on 10.3.9 and prior versions of the OS but fails on 10.4 only with certain JPEG files:
<x-tad-smaller>
NSImage *image = [[NSImage allocWithZone:[</x-tad-smaller><x-tad-smaller>self</x-tad-smaller><x-tad-smaller> zone]] initWithContentsOfFile:imagepath];
NSSize size = [image size];
</x-tad-smaller>Eliminating the obvious; the file exists at "imagepath" and opens/loads correctly. The image on disk is 2592 x 1944. The "size" message returns 1036.8 x 777.6 consistently on multiple 10.4 machines. Both iPhoto and Preview show the correct size of the image in pixels. Apple's Sketch example and my application fail. In a last ditch effort, I tried the following but both "pixelsWide" and "pixelsHigh" return zero:
<x-tad-smaller>NSImage *image = [[NSImage allocWithZone:[</x-tad-smaller><x-tad-smaller>self</x-tad-smaller><x-tad-smaller> zone]] initWithContentsOfFile:imagepath];
NSBitmapImageRep *bitmap = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]];
</x-tad-smaller><x-tad-smaller>if</x-tad-smaller><x-tad-smaller> (bitmap != </x-tad-smaller><x-tad-smaller>nil</x-tad-smaller><x-tad-smaller>)
{
NSLog( </x-tad-smaller><x-tad-smaller>@"rep size: w=%f, h=%f\n"</x-tad-smaller><x-tad-smaller>, [bitmap pixelsWide], [bitmap pixelsHigh] );
}
</x-tad-smaller>
Any ideas or suggestions would be appreciated.
Bret
iDevelop
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden