gpt4 book ai didi

ios - 从 CFData : Arithmetic on a pointer to incomplete type 读取像素字节

转载 作者:行者123 更新时间:2023-11-28 20:09:10 25 4
gpt4 key购买 nike

此代码应该从 CGImageRef 开始获取每个像素的值:

UIImage* image = [UIImage imageNamed:@"mask.bmp"];
CGImageRef aCGImageRef = image.CGImage;

CFDataRef rawData = CGDataProviderCopyData(CGImageGetDataProvider(aCGImageRef));
UInt8 * buf = (UInt8 *) CFDataGetBytePtr(rawData);
int length = CFDataGetLength(rawData);

CFRelease(rawData);

int no_of_channels = 3;
int image_width = SCREEN_WIDTH();

unsigned long row_stride = image_width * no_of_channels; // 960 bytes in this case
unsigned long x_offset = x * no_of_channels;

/* assuming RGB byte order (as opposed to BGR) */
UInt8 r = *(rawData + row_stride * y + x_offset );
UInt8 g = *(rawData + row_stride * y + x_offset + 1);
UInt8 b = *(rawData + row_stride * y + x_offset + 2);

这最后三行可以解决问题,但编译器说它不会将 xy 用作 float .所以我将它们转换为 int,但现在显示为

Arithmetic on a pointer to an incomplete type const struct __CFData

我该如何解决?

最佳答案

您想对字节指针本身进行运算,而不是对 CFData 结构(它的成员是字节)。这意味着使用上面的 buf 变量:

UInt8 r = *(buf + row_stride * y + x_offset );
UInt8 g = *(buf + row_stride * y + x_offset + 1);
UInt8 b = *(buf + row_stride * y + x_offset + 2);

关于ios - 从 CFData : Arithmetic on a pointer to incomplete type 读取像素字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20940885/

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