Skip to content

Instantly share code, notes, and snippets.

@el-hoshino
Created November 25, 2015 03:07
Show Gist options
  • Save el-hoshino/6f33e7e0efaac96d7374 to your computer and use it in GitHub Desktop.
Save el-hoshino/6f33e7e0efaac96d7374 to your computer and use it in GitHub Desktop.
UIImage の画素データを Array で取得する方法 ref: http://qiita.com/lovee/items/74c0310a50d1b752ceb8
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
}
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