-
-
Save sunilsharma08/72e2c4ced1b36ba7e42a9969e67fbeb0 to your computer and use it in GitHub Desktop.
Revisions
-
marchinram revised this gist
Aug 4, 2015 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -15,12 +15,12 @@ extension UIImage { let numberOfComponents = 4 let pixelData = ((Int(size.width) * y) + x) * numberOfComponents let r = CGFloat(data[pixelData]) / 255.0 let g = CGFloat(data[pixelData + 1]) / 255.0 let b = CGFloat(data[pixelData + 2]) / 255.0 let a = CGFloat(data[pixelData + 3]) / 255.0 return UIColor(red: r, green: g, blue: b, alpha: a) } } -
marchinram created this gist
Aug 4, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ import UIKit extension UIImage { subscript (x: Int, y: Int) -> UIColor? { if x < 0 || x > Int(size.width) || y < 0 || y > Int(size.height) { return nil } let provider = CGImageGetDataProvider(self.CGImage) let providerData = CGDataProviderCopyData(provider) let data = CFDataGetBytePtr(providerData) let numberOfComponents = 4 let pixelData = ((Int(size.width) * y) + x) * numberOfComponents let r: UInt8 = data[pixelData] let g: UInt8 = data[pixelData + 1] let b: UInt8 = data[pixelData + 2] let a: UInt8 = data[pixelData + 3] return UIColor(red: CGFloat(r) / 255.0, green: CGFloat(g) / 255.0, blue: CGFloat(b) / 255.0, alpha: CGFloat(a) / 255.0) } }