iDevGames Forums
NSImage and PNG's - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: NSImage and PNG's (/thread-2097.html)



NSImage and PNG's - bmantzey - Nov 29, 2008 08:56 AM

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.


NSImage and PNG's - ThemsAllTook - Nov 29, 2008 09:08 AM

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.


NSImage and PNG's - Frank C. - Nov 29, 2008 12:33 PM

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.


NSImage and PNG's - arekkusu - Nov 29, 2008 07:01 PM

Or you could just read the documentation and use the right API.