Swift 3中CGImage的绘制直方图

编程入门 行业动态 更新时间:2024-10-27 05:25:44
本文介绍了Swift 3中CGImage的绘制直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

尝试将库从Swift 2版本转换为Swift 3版本时, vImageHistogramCalculation_ARGB8888 方法有问题。问题在于该方法仅接受

I have a problem with vImageHistogramCalculation_ARGB8888 method while trying to convert library from Swift 2 to Swift 3 version. The problem is that the method accepts "histogram" argument only as

UnsafeMutablePointer<UnsafeMutablePointer<T>?>

但是Swift 3构造

but Swift 3 construction

let histogram = UnsafeMutablePointer<UnsafeMutablePointer<vImagePixelCount>>(mutating: rgba)

返回未包装的值,因此无法将其强制转换为正确的类型。

return unwrapped value, so I can't cast it to properly type.

编译器错误是:

:无法为类型$ b调用初始化程序$ b'UnsafeMutablePointer?>'和类型为'(muting: [UnsafeMutablePointer])'的参数列表'

: Cannot invoke initializer for type 'UnsafeMutablePointer?>' with an argument list of type '(mutating: [UnsafeMutablePointer])'

您有一些想法吗?我试图添加?到直方图常量,但随后收到错误:

Have you some ideas? I tried to add "?" to histogram constant but then I receive error:

'init'不可用:对$使用$ withMemoryRebound(to:capacity:_) b $ b暂时将内存视为另一种与布局兼容的类型。

'init' is unavailable: use 'withMemoryRebound(to:capacity:_)' to temporarily view memory as another layout-compatible type.

有一些编译器建议,但我不知道如何使用它。

there is some compiler suggestion but I have no idea how can use it.

推荐答案

是否已转换为 UnsafeMutablePointer< vImagePixelCount>? let alphaPtr = UnsafeMutablePointer<vImagePixelCount>(mutating: alpha) as UnsafeMutablePointer<vImagePixelCount>?

完成,编译示例:

var inBuffer = vImage_Buffer() // set your buffer here let alpha = [UInt](repeating: 0, count: 256) let red = [UInt](repeating: 0, count: 256) let green = [UInt](repeating: 0, count: 256) let blue = [UInt](repeating: 0, count: 256) let alphaPtr = UnsafeMutablePointer<vImagePixelCount>(mutating: alpha) as UnsafeMutablePointer<vImagePixelCount>? let redPtr = UnsafeMutablePointer<vImagePixelCount>(mutating: red) as UnsafeMutablePointer<vImagePixelCount>? let greenPtr = UnsafeMutablePointer<vImagePixelCount>(mutating: green) as UnsafeMutablePointer<vImagePixelCount>? let bluePtr = UnsafeMutablePointer<vImagePixelCount>(mutating: blue) as UnsafeMutablePointer<vImagePixelCount>? let rgba = [redPtr, greenPtr, bluePtr, alphaPtr] let histogram = UnsafeMutablePointer<UnsafeMutablePointer<vImagePixelCount>?>(mutating: rgba) let error = vImageHistogramCalculation_ARGB8888(&inBuffer, histogram, UInt32(kvImageNoFlags)) // alpha, red, green, blue are set now

更多推荐

Swift 3中CGImage的绘制直方图

本文发布于:2023-07-30 16:21:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1251002.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:直方图   Swift   CGImage

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!