Re: Get pixel data as array from UIImage/CGImage in swift
问题 This code works for me (Swift 2 playground) in Gray scale, loading a colour .BMP image... Get pixel data as array from UIImage/CGImage in swift ... but if I change bytesPerPixel to 3 (or 4) and use let colorSpace = CGColorSpaceCreateDeviceRGB() ...the code still runs with no errors, but pixel values are all zeros. Any suggestions as to how to fix that? 回答1: You probably forgot the CGImageAlphaInfo parameter. For color images, if you assume bytesPerPixel to be 4, you need to set either RGBA