Get the correct image width and height of an NSImage

后端 未结 5 2011
北荒
北荒 2021-02-04 02:20

I use the code below to get the width and height of a NSImage:

NSImage *image = [[[NSImage alloc] initWithContentsOfFile:[NSString stringWithFormat:s]] autorelea         


        
5条回答
  •  无人及你
    2021-02-04 02:46

    Dimensions of your image in pixels is stored in NSImageRep of your image. If your file contains only one image, it will be like this:

    NSImageRep *rep = [[image representations] objectAtIndex:0];
    NSSize imageSize = NSMakeSize(rep.pixelsWide, rep.pixelsHigh);
    

    where image is your NSImage and imageSize is your image size in pixels.

提交回复
热议问题