NSImage of various sizes in code other than Finder / Preview

I have several images that I use in my application (one of them is attached). The strange thing is that the actual size of the image (shown by the search device and the preview) is 1200x701 px.

When I access the image from the code and how its size, I get 360x210px. What's happening?

The code I use to get the image size:


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 newImg is the same image that was specified and uploaded - I still display it in NSImageView, so I see. Only the size made with -sizeis incorrect.

This image:

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

+3
3

, [NSImage size] , . NSImageRep , High pixelsWide . , -, 72 dpi.

+6
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);
+1

An NSImagecan contain several representations of the same image, each of which has different sizes. I would look at the method -representationson NSImage, and then take a look at each object NSImageRepreturned in the array to see what it all has.

0
source

Source: https://habr.com/ru/post/1748866/


All Articles