【问题标题】:Get pixel size of a NSBitmapImageRep?获取 NSBitmapImageRep 的像素大小?
【发布时间】:2009-03-20 04:04:18
【问题描述】:

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


    【解决方案1】:

    【讨论】:

    • @peter:你在哪里找到这些信息的?我看了看,它不在 NSBitmapImageRep 的文档中。
    • 点击链接,你会看到这些方法(以及它们的文档)在 NSBitmapImageRep 的超类 NSImageRep 中。
    猜你喜欢
    • 2012-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-13
    • 1970-01-01
    • 2018-07-11
    • 2020-06-29
    • 2012-07-20
    相关资源
    最近更新 更多