![](/img/trans.png)
[英]Cannot invoke initialiser for type ‘UInt32’ with an argument list of type ‘(String.UTF8View)
[英]Cannot invoke initializer for type 'CGBitmapInfo' with an argument list of type '(UInt32)'
我将图像作为纹理添加到金属球体中。 使用swift 2.0,但出现错误CGBitmapInfo(options),它说:无法为类型为'(UInt32)'的参数列表调用'CGBitmapInfo'类型的初始化程序...有人知道如何修复它吗? 这是我的代码:
func textureForImage(image:UIImage, device:MTLDevice) -> MTLTexture?
{
let imageRef = image.CGImage
let width = CGImageGetWidth(imageRef)
let height = CGImageGetHeight(imageRef)
let colorSpace = CGColorSpaceCreateDeviceRGB()
let rawData = calloc(height * width * 4, sizeof(UInt8))
let bytesPerPixel = 4
let bytesPerRow = bytesPerPixel * width
let bitsPerComponent = 8
let options = CGImageAlphaInfo.PremultipliedLast.rawValue | CGBitmapInfo.ByteOrder32Big.rawValue
let context = CGBitmapContextCreate(rawData,
width,
height,
bitsPerComponent,
bytesPerRow,
colorSpace,
CGBitmapInfo(options))
CGContextDrawImage(context, CGRectMake(0, 0, CGFloat(width), CGFloat(height)), imageRef)
let textureDescriptor = MTLTextureDescriptor.texture2DDescriptorWithPixelFormat(.RGBA8Unorm,
width: Int(width),
height: Int(height),
mipmapped: true)
let texture = device.newTextureWithDescriptor(textureDescriptor)
let region = MTLRegionMake2D(0, 0, Int(width), Int(height))
texture.replaceRegion(region,
mipmapLevel: 0,
slice: 0,
withBytes: rawData,
bytesPerRow: bytesPerRow,
bytesPerImage: bytesPerRow * height)
free(rawData)
return texture
}
在当前版本的Swift中, CGBitmapContextCreate
的最终参数是UInt32
,因此,代替上面的CGBitmapInfo(options)
,您应该仅传递options
(分配给options
的表达式推断为UInt32
类型)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.