gpt4 book ai didi

iOS - Objective C - 无法使用 UInt8 渲染像素

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:29:39 25 4
gpt4 key购买 nike

我尝试使用 CIAreaAverage 从特定图像中捕捉平均颜色。捕捉操作进行得很顺利,过滤器的 outputImage 给了我单个像素 CIImage

当尝试使用 uint8_t 捕获 RGB 信息时出现问题

"pixel" (uint8_t) always empty (" ").

我很确定我的渲染上下文不是 nil,只是 "render" 操作出错了。

我不知道如何正确地从 CIImage 中捕获 RGB 数据。

enter image description here

最佳答案

pixel 应该作为参数直接传递给 render:toBitmap:rowBytes:bounds:format: 函数,而不是作为指针。

正确的函数调用应该是:

[con render: average.outputImage toBitmap: pixel rowBytes: 4 bounds: onePixel format: kCIFormatRGBA8] 

pixel 已经是一个指针,因此通过将指针传递给 pixelpixel 指向的内存地址会发生变化。之后访问 pixel[0] 会访问现在可能无效的内存地址,这就是您的程序因 EXC_BAD_ACCESS 而崩溃的原因。

关于iOS - Objective C - 无法使用 UInt8 渲染像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49994310/

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