Created
November 25, 2015 03:07
-
-
Save el-hoshino/6f33e7e0efaac96d7374 to your computer and use it in GitHub Desktop.
UIImage の画素データを Array で取得する方法 ref: http://qiita.com/lovee/items/74c0310a50d1b752ceb8
This file contains 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 getByteArrayFromImage(imageRef: CGImageRef) -> [UInt8] { | |
let data = CGDataProviderCopyData(CGImageGetDataProvider(imageRef)) | |
let length = CFDataGetLength(data) | |
var rawData = [UInt8](count: length, repeatedValue: 0) | |
CFDataGetBytes(data, CFRange(location: 0, length: length), &rawData) | |
return rawData | |
} |
This file contains 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 imageRef = UIImage(named: "SomeImage.png")!.CGImage! | |
let imageData = getByteArrayFromImage(imageRef) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment