NSImageRep doesn't give the proper size in all cases? Doh!

6 views
Skip to first unread message

Jeremy

unread,
Jul 1, 2014, 1:27:09 AM7/1/14
to byu-coc...@googlegroups.com
Hey guys.  I could use some mac coding help!

I've got an image that is loaded via a passed in file path.  On iOS this works as expected, but on macOS sometimes the image size is incorrect.  Here is the appropriate portion of the method, it's pretty straightforward.

-(void)setSourceImage:(NSString *)sourceImage
{
_sourceImage = [sourceImage copy];
#if TARGET_OSX
NSImageRep* atlas = [NSImageRep imageRepWithContentsOfFile:_sourceImage];
#else
UIImage* atlas = [UIImage imageWithContentsOfFile:_sourceImage];
#endif
_imageSize = atlas.size;
_atlasTexture = [SKTexture textureWithImageNamed:_sourceImage];


NSLog(@"texture image: %@\rSize (%f, %f)", _sourceImage, _atlasTexture.size.width, _atlasTexture.size.height);

...
}

With the image in question, the reported size is logged like this on the mac:
Size (259.605634, 1330.478873)

and on iOS it is correct:
Size (256.000000, 1312.000000)

I understand that images on MacOS work a bit differently, and depend more on their overall context, which is why NSImage isn't being used here.  However, getting the real dimensions of an image loaded from disk should not be this difficult...  right?  =)

Reference to some more code details, including the image I am looking at, can be found here: 

Thanks for any insight!

--Jeremy
Reply all
Reply to author
Forward
0 new messages