From bb02b247a7f08d6cc2091d6fee2bbbd79a6cfe07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=93=E6=B3=A2?= Date: Sat, 4 Mar 2017 14:49:59 +0800 Subject: [PATCH] fix image alpha premultiplied --- FXBlurView/FXBlurView.m | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/FXBlurView/FXBlurView.m b/FXBlurView/FXBlurView.m index 73c6f91..55d2b22 100755 --- a/FXBlurView/FXBlurView.m +++ b/FXBlurView/FXBlurView.m @@ -117,10 +117,26 @@ - (UIImage *)blurredImageWithRadius:(CGFloat)radius iterations:(NSUInteger)itera free(buffer2.data); free(tempBuffer); + CGImageAlphaInfo alphaInfo = CGImageGetBitmapInfo(imageRef) & kCGBitmapAlphaInfoMask; + + //Since iOS8 it's not allowed anymore to create contexts with unmultiplied Alpha info + if (alphaInfo == kCGImageAlphaLast) { + alphaInfo = kCGImageAlphaPremultipliedLast; + } + if (alphaInfo == kCGImageAlphaFirst) { + alphaInfo = kCGImageAlphaPremultipliedFirst; + } + + //reset the bits + CGBitmapInfo newBitmapInfo = CGImageGetBitmapInfo(imageRef) & ~kCGBitmapAlphaInfoMask; + + //set the bits to the new alphaInfo + newBitmapInfo |= alphaInfo; + //create image context from buffer CGContextRef ctx = CGBitmapContextCreate(buffer1.data, buffer1.width, buffer1.height, 8, buffer1.rowBytes, CGImageGetColorSpace(imageRef), - CGImageGetBitmapInfo(imageRef)); + newBitmapInfo); //apply tint if (tintColor && CGColorGetAlpha(tintColor.CGColor) > 0.0f)