开发者

NSImage different size in code different shown by Finder/Preview

I have a couple of images that i use in my application(one of them is attached). The strange thing is that the real image size(shown by finder and preview) is 1200x701 px.

When I access image from the code and as for its size, I get 360x210px. What is going on?

Code I'm using to get the size of the image:


NSImage *newImg =  [[NSImage alloc] initWithContentsOfURL:
                   [NSURL URLFromPasteboard:[sender draggingPasteboard]]];
float h = [newImg size].height; //height is 210px - should be 701px
float w = [newImg size].width;  //width is 320px - should be 1200px

The content of the newImg is the same image that has been pointed and load开发者_JS百科ed - I display it in the NSImageView anyway so I see. Just the size taken with -size is wrong.

This is the image:

alt text http://www.tomaszkrasnyk.yoyo.pl/image.jpg


I believe that -[NSImage size] returns the size in points, not pixels. That's why NSImageRep has both a size method and pixelsHigh and pixelsWide methods. Your image is apparently not at a 72 dpi resolution.


NSImageRep *imgRep = [NSImageRep imageRepWithContentsOfFile:imagePath];
int imageWidth = (int)[imgRep pixelsWide];
int imageHeight = (int)[imgRep pixelsHigh];
imgRep = nil;

NSLog(@"original image width: %d",imageWidth);
NSLog(@"original image height: %d",imageHeight);


An NSImage can contain multiple representations of the same image, each at different sizes. I'd take a look at the -representations method on NSImage, and then take a look at each NSImageRep object returned in the array to see what all it has.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜