大佬教程收集整理的这篇文章主要介绍了ios – swift 2.0后的CGBitmapInfo alpha蒙版,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
除了这个功能,我已经能够修复一切:
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类型的预期参数
以上是大佬教程为你收集整理的ios – swift 2.0后的CGBitmapInfo alpha蒙版全部内容,希望文章能够帮你解决ios – swift 2.0后的CGBitmapInfo alpha蒙版所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。