cocoa - 获取 NSBitmapImageRep 的像素大小?

标签 cocoa

获取 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] 一样简单的东西来说,似乎需要输入大量的内容...

我在互联网上看到过一些像这样查询大小的帖子(这不在文档中):

NSSize imageSize = [bitmap size];

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

最佳答案

关于cocoa - 获取 NSBitmapImageRep 的像素大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/664944/

相关文章:

objective-c - NSBox 对焦环?

macos - 如何禁用窗口恢复?

objective-c - 在没有 NSAutoReleasePool 的情况下使用 autoReleased 对象?

cocoa - 自动调整 NSView 大小

objective-c - 隐藏 Mac OS X Launchpad 上的图标而不修改 DB?

objective-c - 操作 HTML

objective-c - 从数组中检索结构体时出现问题

objective-c - 检测 NSOpenGLView 上的触摸

objective-c - NSString drawAtPoint 文本未显示

macos - 带有命令行输入重定向的 NSTask