Get the correct image width and height of an NSImage

后端 未结 5 2013
北荒
北荒 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:27

    the direct API gives also the correct results

    CGImageRef cgImage = [oldImage CGImageForProposedRect:nil context:context hints:nil];
    size_t width = CGImageGetWidth(cgImage);
    size_t height = CGImageGetHeight(cgImage);
    

提交回复
热议问题