除了这个功能,我已经能够修复一切:
func hnk_decompressedImage() -> UIImage! { let originalimageRef = self.CGImage let originalBitmAPInfo = CGImageGetBitmAPInfo(originalimageRef) let AlphaInfo = CGImageGetAlphaInfo(originalimageRef) // See: https://stackoverflow.com/questions/23723564/which-cgimageAlphainfo-should-we-use var bitmAPInfo = originalBitmAPInfo switch (AlphaInfo) { case .None: bitmAPInfo &= ~CGBitmAPInfo.AlphaInfoMask bitmAPInfo |= CGBitmAPInfo(rawValue: CGImageAlphaInfo.NoneskipFirst.rawValue) case .PremultiplIEdFirst,.PremultiplIEdLast,.NoneskipFirst,.NoneskipLast: break case .Only,.Last,.First: // Unsupported return self } let colorSpace = CGcolorSpaceCreateDeviceRGB() let pixelSize = CGSizeMake(self.size.wIDth * self.scale,self.size.height * self.scale) if let context = CGBitmapContextCreate(nil,Int(ceil(pixelSize.wIDth)),Int(ceil(pixelSize.height)),CGImageGetBitsPerComponent(originalimageRef),colorSpace,bitmAPInfo) { let imageRect = CGRectMake(0,pixelSize.wIDth,pixelSize.height) UIGraphicsPushContext(context) // Flip coordinate system. See: https://stackoverflow.com/questions/506622/cgcontextdrawimage-draws-image-upsIDe-down-when-passed-uiimage-cgimage CGContextTranslateCTM(context,pixelSize.height) CGContextScaleCTM(context,1.0,-1.0) // UIImage and drawInRect takes into account image orIEntation,unlike CGContextDrawImage. self.drawInRect(imageRect) UIGraphicsPopContext() let decompressedImageRef = CGBitmapContextCreateImage(context) let scale = UIScreen.mainScreen().scale let image = UIImage(CGImage: decompressedImageRef,scale:scale,orIEntation:UIImageOrIEntation.Up) return image } else { return self }}
具体来说,这是抛出错误的代码行:
bitmAPInfo &= ~CGBitmAPInfo.AlphaInfoMask bitmAPInfo |= CGBitmAPInfo(rawValue: CGImageAlphaInfo.NoneskipFirst.rawValue)
错误:一元运算符’〜’不能应用于CGBitmAPInfo类型的 *** 作数
bitmAPInfo |= CGBitmAPInfo(rawValue: CGImageAlphaInfo.NoneskipFirst.rawValue)
错误:二进制运算符’| =’不能应用于类型为’CGBitmAPInfo’的 *** 作数
if let context = CGBitmapContextCreate(nil,bitmAPInfo)
错误:无法将类型“CGBitmAPInfo”的值转换为UInt32类型的预期参数
解决方法 错误:无法将类型“CGBitmAPInfo”的值转换为UInt32类型的预期参数Swift 2.0实际上期望一个UInt32而不是一个CGBitMAPInfo对象,所以你应该在CGBitMAPInfo中取出一个UInt32变量.
CGBitmapContextCreate( nil,bitmAPInfo.rawValue)
https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CGBitmapContext/#//apple_ref/c/func/CGBitmapContextCreate
总结以上是内存溢出为你收集整理的ios – swift 2.0后的CGBitmapInfo alpha蒙版全部内容,希望文章能够帮你解决ios – swift 2.0后的CGBitmapInfo alpha蒙版所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)