I want to get color of all the individual pixels of an image. To elaborate Let say I have an image named "SampleImage" having 400 x 400 pixels Basically I want to create a grid from 'SampleImage' which will have 400 x 400 squares each filled with color corresponding to the specific pixel in 'SampleImage'.
I know this is a little abstract, but I am novice in iOS and don't know where to start from. Thanks in advance!
If you are a novice, you should consider doing something easier first. Anyway, what you need to do is set up a
CGContextRef
viaCGBitmapContextCreate
with enough data to hold your image. Once you create it, you need to render your image into it viaCGDrawImage
. After that you will have a pointer to every pixel in your image. The code is similar to Nishant's answer, but instead of 1x1, you will use 400x400 to get all of the pixels at once.Use this : Here is more efficient solution:
Hope it helps you.
This code worked flawlessly for me -: