Skip to content

Instantly share code, notes, and snippets.

@shalyf
Created February 11, 2018 02:37
Show Gist options
  • Save shalyf/041811b0679742b9702e2739973f6028 to your computer and use it in GitHub Desktop.
Save shalyf/041811b0679742b9702e2739973f6028 to your computer and use it in GitHub Desktop.
判断像素点是否是黑色
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