首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取NSBitmapImageRep的像素大小?

获取NSBitmapImageRep的像素大小?
EN

Stack Overflow用户
提问于 2009-03-20 04:04:19
回答 1查看 1.6K关注 0票数 2

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

这就是我现在要做的:

代码语言:javascript
复制
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;

对于像位图getWidth这样简单的东西,似乎需要大量的输入……

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

代码语言:javascript
复制
NSSize imageSize = [bitmap size];

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-03-20 05:13:43

  • [rep pixelsWide]
  • [rep pixelsHigh]
票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/664944

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档