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

Pixelated image is blue since iOS 11.4 #1

Open
ThibaultVlacich opened this issue Jun 13, 2018 · 1 comment
Open

Pixelated image is blue since iOS 11.4 #1

ThibaultVlacich opened this issue Jun 13, 2018 · 1 comment

Comments

@ThibaultVlacich
Copy link

Hello,

I seem to have an issue when using your lib since iOS 11.4, when I pixelate an image, the image is blue.

Here's my code:

extension UIImage {
    
    func pixelate(resolution: CGFloat) -> UIImage? {
        guard let cgImage = self.cgImage,
            let pixelatedImage = Pixelate.create(pixels: cgImage, layers: PixelateLayer(.square, resolution: resolution))
            else { return nil }
        
        return UIImage(cgImage: pixelatedImage, scale: self.scale, orientation: self.imageOrientation)
    }
    
}

When I use this code to pixelate an image from an UIImage instance, like this for example:

let image = UIImage(named: "imageName")
let pixelatedImage = image.pixelate(resolution: 10)

imageView.image = pixelatedImage

The image showed in the image view is completely blue. It's correctly pixelated, but blue. An it seems to have appeared with iOS 11.4, it was working fine before.

Any idea why?

@JohanDufau
Copy link

JohanDufau commented Jun 14, 2018

It seems like there is an issue when interpreting a CGImage with alphaInfo == noneSkipFirst in Pixelate.swift file on line 169.
According to Apple, there is more treatment to do:

There is no alpha channel. If the total size of the pixel is greater than the space required for the number of color components in the color space, the most significant bits are ignored.

A workaround for this would be: reload your image with UIImageJPEGRepresentation(image, 1.0) to get a normal alphaInfo such as noneSkipLast which works well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants