Cocoa 获取NSBitmapImageRep的像素大小?

Cocoa 获取NSBitmapImageRep的像素大小?,cocoa,Cocoa,获取NSBitmapImageRep大小(宽度和高度)的最佳方法是什么 这就是我现在正在做的: NSBitmapImageRep *bitmap; NSInteger samplesPerPixel = [bitmap samplesPerPixel]; NSInteger bytesPerPlane = [bitmap bytesPerPlane]; NSInteger bytesPerRow = [bitmap bytesPerRow]; NSInteger numberOfPlanes

获取NSBitmapImageRep大小(宽度和高度)的最佳方法是什么

这就是我现在正在做的:

NSBitmapImageRep *bitmap;

NSInteger samplesPerPixel = [bitmap samplesPerPixel];
NSInteger bytesPerPlane = [bitmap bytesPerPlane];
NSInteger bytesPerRow = [bitmap bytesPerRow];
NSInteger numberOfPlanes = [bitmap numberOfPlanes];

NSUInteger numPixels = numberOfPlanes * bytesPerPlane / samplesPerPixel;
NSUInteger width = bytesPerRow / samplesPerPixel;
NSUInteger height = numPixels / width;
似乎输入了很多东西,应该像[bitmap getWidth]一样简单

我在互联网上看到过一些帖子,它们质疑这样的尺寸(文档中没有这个):

但是这些值似乎并不代表图像的像素尺寸(例如,我得到的浮点值是122.869835,而不是256,这是图像的实际像素宽度)。


@peter:你在哪里找到这些信息的?我查看了,但它不在NSBitmapImageRep的文档中。单击链接,您将看到这些方法(及其文档)在NSBitmapImageRep的超类NSImageRep中。
NSSize imageSize = [bitmap size];