How to get resolution of an NSImage or NSBitmapImageRep?

Member
Posts: 28
Joined: 2003.10
Post: #1
I can obtain the size (pixel dimensions) of an NSImage or NSImageBitmapImageRep, but because NSImage does odd stuff adjusting the size to fit the DPI when it's loaded then if a texture has a non-standard DPI my OpenGL texture code an choke on the resulting non-power-of-two pixel dimensions.

I'd just like to be able to reject files that aren't 72dpi x 72dpi, but can't see a way to do it.

Any help (ideally in Cocoa/Obj-C) would be very appreciated.

-- Giles Williams
Oolite - retro space-sim agogo
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Don't use NSBitmapImageRep to load textures? There's a perfectly good QuickTime API for that that is actually usable for the purpose Smile
Quote this message in a reply
Member
Posts: 78
Joined: 2002.06
Post: #3
NSSize s = [rep size];
float wRes = 72.0 * [rep pixelsWide] / s.width;
float hRes = 72.0 * [rep pixelsHigh] / s.height;
Quote this message in a reply
Member
Posts: 28
Joined: 2003.10
Post: #4
OneSadCookie Wrote:Don't use NSBitmapImageRep to load textures? There's a perfectly good QuickTime API for that that is actually usable for the purpose Smile

Unfortunately I don't want to use QuickTime in Oolite since its methods can't easily be crossed to Linux.

-- Giles Williams
Oolite - retro space-sim agogo
Quote this message in a reply
Member
Posts: 28
Joined: 2003.10
Post: #5
willThimbleby Wrote:NSSize s = [rep size];
float wRes = 72.0 * s.width / [rep pixelsWide];
float hRes = 72.0 * s.height / [rep pixelsHigh];

Thanks - that tells me everything I need! Smile

-- Giles Williams
Oolite - retro space-sim agogo
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  DPI and Resolution for Graphics mickyg 9 8,911 Apr 27, 2012 03:02 PM
Last Post: Andres Calil
  Strange OpenGl or NSBitmapImageRep error magnusrw 4 3,324 Apr 24, 2009 11:13 AM
Last Post: magnusrw
  Basic NSImage drawing help please! xenocide 6 5,691 Feb 2, 2009 11:01 AM
Last Post: FlamingHairball
  NSImage and PNG's bmantzey 3 5,090 Nov 29, 2008 07:01 PM
Last Post: arekkusu
  NSBitmapImageRep/CIImage questions Caveman 6 6,245 Sep 6, 2008 04:37 PM
Last Post: ThemsAllTook