获取 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/