nicklockwood / FXBlurView

[DEPRECATED]
Other
4.94k stars 713 forks source link

Blur 8 Bits Image will be crash #106

Open matthewyan opened 9 years ago

matthewyan commented 9 years ago

My image is 8 bit gray image, when I blur it, it crashed

I fixed by this code:

- (UIImage *)blurredImageWithRadius:(CGFloat)radius iterations:(NSUInteger)iterations tintColor:(UIColor *)tintColor
{
    //image must be nonzero size
    if (floorf(self.size.width) * floorf(self.size.height) <= 0.0f) return self;

    //boxsize must be an odd integer
    uint32_t boxSize = (uint32_t)(radius * self.scale);
    if (boxSize % 2 == 0) boxSize ++;

    //create image buffers
    CGImageRef imageRef = self.CGImage;

    // Here:fix crash
    size_t sizeBit = CGImageGetBitsPerPixel(imageRef);
    if (sizeBit == 8) {
            return self;
    }
    ...
}
mariancerny commented 9 years ago

Try this fork: https://github.com/Vienta/FXBlurView It adds conversion of non-ARGB8888 images into ARGB8888.