ios - How to find the colour of an individual pixel in UIImage in swift -


i have following swift code.

let resolution = [imageview.frame.size.width, imageview.frame.size.height]  x in 0...int(resolution[0]) {     y in 0...int(resolution[1]) {         let coordinate = [x, y]         //find colour of pixel here     } } 

i want able find colour being displayed each individual pixel in photo. there way modify code have put "//find colour of pixel here" print rgb value of pixel @ coordinate represented constant coordinate?

you can try following:

var pixel : [uint8] = [0, 0, 0, 0] var colorspace = cgcolorspacecreatedevicergb() let bitmapinfo = cgbitmapinfo(cgimagealphainfo.premultipliedlast.rawvalue) let context = cgbitmapcontextcreate(unsafemutablepointer(pixel), 1, 1, 8, 4, colorspace, bitmapinfo) 

hope helps!!


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -