gpt4 book ai didi

objective-c - 如何访问 NSBitmapImageRep 的像素?

转载 作者:行者123 更新时间:2023-12-03 18:05:45 26 4
gpt4 key购买 nike

我有一个像这样创建的NSBitmapImageRep:

NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] 
initWithBitmapDataPlanes:NULL
pixelsWide:waveformSize.width
pixelsHigh:waveformSize.height
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:YES
colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:0
bitsPerPixel:0];

现在我想访问像素数据,因此我使用以下方法获得指向像素平面的指针

unsigned char *bitmapData;
[imageRep getBitmapDataPlanes:&bitmapData];

根据the Documentation这将返回一个包含五个字符指针的 C 数组。但它怎么能做到这一点呢?由于参数的类型是unsigned char **,它只能返回char数组,而不能返回char数组< em>指针。

所以,这让我想知道如何访问各个像素。您知道如何做到这一点吗?

(我知道有一个方法– setColor:atX:y:,但如果为大位图的每个像素调用它似乎会相当慢。)

最佳答案

如果您只想迭代像素,-bitmapData 应该就是您所需要的。

关于objective-c - 如何访问 NSBitmapImageRep 的像素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2526001/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com