Sto utilizzando una libreria da questo repository github https://github.com/Haneke/HanekeSwift per memorizzare nella cache le immagini scaricate da un server. Dopo l'aggiornamento a swift 2.0, tutto è incasinato.CGBitmapInfo alpha mask after swift 2.0
Sono stato in grado di risolvere tutto, ma questa funzione:
func hnk_decompressedImage() -> UIImage! {
let originalImageRef = self.CGImage
let originalBitmapInfo = CGImageGetBitmapInfo(originalImageRef)
let alphaInfo = CGImageGetAlphaInfo(originalImageRef)
// See: http://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), 0, colorSpace, bitmapInfo) {
let imageRect = CGRectMake(0, 0, pixelSize.width, pixelSize.height)
UIGraphicsPushContext(context)
// Flip coordinate system. See: http://stackoverflow.com/questions/506622/cgcontextdrawimage-draws-image-upside-down-when-passed-uiimage-cgimage
CGContextTranslateCTM(context, 0, 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
}
}
In particolare ciò sono le righe di codice che stanno gettando gli errori:
bitmapInfo &= ~CGBitmapInfo.AlphaInfoMask
bitmapInfo |= CGBitmapInfo(rawValue: CGImageAlphaInfo.NoneSkipFirst.rawValue)
errore: operatore unario '~' non può essere applicato a operando di tipo CGBitmapInfo
errorebitmapInfo |= CGBitmapInfo(rawValue: CGImageAlphaInfo.NoneSkipFirst.rawValue)
: operatore binario '| =' non può essere applicato ad un operando di tipo di errore
if let context = CGBitmapContextCreate(nil, Int(ceil(pixelSize.width)), Int(ceil(pixelSize.height)), CGImageGetBitsPerComponent(originalImageRef), 0, colorSpace, bitmapInfo)
'CGBitmapInfo': Impossibile convertire il valore di tipo 'CGBitmapInfo' all'argomento previsto di tipo UInt32