Created
February 11, 2018 02:37
-
-
Save shalyf/041811b0679742b9702e2739973f6028 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
let isBlackColor = { (x: Int, y: Int) -> Bool in | |
let byteIndex = (bytesPerRow * y) + x * bytesPerPixel | |
let r = CGFloat(rawData[byteIndex]) | |
let g = CGFloat(rawData[byteIndex + 1]) | |
let b = CGFloat(rawData[byteIndex + 2]) | |
// https://stackoverflow.com/a/12043228 | |
let luma = 0.2126 * r + 0.7152 * g + 0.0722 * b | |
return luma < 40 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment