NSImage and PNG's

Member
Posts: 241
Joined: 2008.07
Post: #1
I have a simple Cocoa app that loads and displays a texture. The view that it is displayed in is 1024 by 512 because that is most likely the dimensions of the images that I'll be working with. I have a PNG file that opens up in Preview as 1024x512, in other apps as such, and the Finder indicates that that's the size of it as well. For some reason,

Code:
NSImage *image = [[NSImage alloc] initWithContentsOfFile:texturePath];
NSSize imageSize = [image size];

imageSize is 458 by 229 every time. I tried resaving it, no change but when I saved it as a TGA file, it loads and displays correctly.

All of the images I'll be receiving will be in PNG format because they'll be loaded into the iPhone. I could convert them all but it would be nice if I didn't have to. Does anyone know why PNG files are loading like that? Thanks in advance.
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
NSImage does some annoying automatic DPI conversion, which can screw with reported sizes. Also, you won't necessarily be able to get bitmap data out of it in a known pixel format. You'd be better off using ImageIO or libpng. ImageIO premultiplies data, so if that's a problem, go with libpng.
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #3
If you have control over the images you're loading, try this: http://www.nothings.org/stb_image.c

It's the least cumbersome image loader I've run across and has no dependancies - just plop it in and go.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #4
Or you could just read the documentation and use the right API.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Basic NSImage drawing help please! xenocide 6 5,740 Feb 2, 2009 11:01 AM
Last Post: FlamingHairball
  NSImage PDF -> JPG unknown 3 3,960 Oct 23, 2005 08:36 PM
Last Post: PowerMacX
  How to get resolution of an NSImage or NSBitmapImageRep? aegidian 4 5,758 Oct 18, 2005 02:39 AM
Last Post: aegidian
  Help with NSImage and NSString... Joseph Duchesne 2 4,940 Sep 30, 2005 02:21 PM
Last Post: unknown
  NSImage -> Jigsaw peices unknown 5 3,742 Sep 29, 2005 07:00 AM
Last Post: unknown