【发布时间】:2014-06-18 12:39:46
【问题描述】:
我正在尝试将此 objc 代码转换为 swift:
CGContextRef contextRef = CGBitmapContextCreate(NULL,
proposedRect.size.width,
proposedRect.size.height,
CGImageGetBitsPerComponent(imageRef),
0,
colorSpaceRef,
(CGBitmapInfo)kCGImageAlphaPremultipliedFirst);
NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithGraphicsPort:contextRef flipped:NO];
到目前为止,我最终得到了这个:
var bitmapContext: CGContext = CGBitmapContextCreate(data, UInt(proposedRect.width), UInt(proposedRect.height), CGImageGetBitsPerComponent(image), 0, colorSpace, CGBitmapInfo(CGImageAlphaInfo.PremultipliedFirst.toRaw()))
let context = NSGraphicsContext(graphicsPort: bitmapContext, flipped: false)
问题在于CGBitmapContextCreate 返回CGContext 类型,而NSGraphicsContext 初始化程序接受graphicsPort 作为CMutableVoidPointer 类型。那么如何将CGContext 转换为CMutableVoidPointer?
在此处找到相关的反向类型转换,但对我没有太大帮助 How to convert COpaquePointer in swift to some type (CGContext? in particular)
【问题讨论】:
-
传递
&contextRef有效吗? -
它没有。
&contextRef有CGContextRef *类型,这不是我需要的。基本上我需要简单的演员CGContextRefasvoid *
标签: pointers types casting swift void