Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix image alpha premultiplied #140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion FXBlurView/FXBlurView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down