Created
May 24, 2016 07:40
-
-
Save quangtqag/d00f9ddf3cb8d2b298bf5c5c0108ae16 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func grayScale() -> UIImage { | |
| let width = self.size.width | |
| let height = self.size.height | |
| let imageRect:CGRect = CGRectMake(0, 0, width, height) | |
| let colorSpace = CGColorSpaceCreateDeviceGray() | |
| let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.None.rawValue) | |
| let context = CGBitmapContextCreate(nil, Int(width), Int(height), 8, 0, colorSpace, bitmapInfo.rawValue) | |
| CGContextDrawImage(context, imageRect, self.CGImage) | |
| let imageRef = CGBitmapContextCreateImage(context) | |
| let grayScaleImage = UIImage(CGImage: imageRef!) | |
| return grayScaleImage | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment