This is the Case
i have an unsigned char pointer to BMP image data
after i loop with the pointer i achieved a byte array contain int values 0 - 255
What i want is convert this values in the array to BMP image to display it in UIImage.
**the image is in gray scale
This code snippet is from this blog, I recommend you take a look there and the project site in Github
Also Note that this class method works for RGB8 Images, so you will need to make changes in
bitsPerPixel
(it should be 8 for grayscale),bytesPerRow
(1 * width),bufferLength
(remove * 4) and createcolorSpaceRef
usingCGColorCreateGenericGray
instead.Also I've noticed that creating the color space with
CGColorCreateGenericGray
assumes that your array has alpha info. So maybe you should add an alpha byte for each pixel to make it work properly.I would imagine something like this. Untested, so be ready to tweak :)
Because of the accepted answer is to long, I've wrote another solution: