2

I need to pass my UIImage to an image-processing algorithm that takes int array of the bitmap in rgb565 format.

Later, it returns image-processed int array which I need to convert back to UIImage.

See it's syntax:

int* ImageProcessingAlgorithm(int bitmapArray[], int width, int height);

I searched many places but none seem to have UIImage-to-int-array and vice versa conversion. Nearest I found was this but this deals with char array - I tried fitting it for my purpose but I keep getting various access errors and leaks in UIKit library functions. Maybe I am not managing memory properly or some mistake in int-to-unsigned char-to-int conversion.

I can deal with that part, but still I am not sure it fits my image processing algorithm format (rgb565).

I am newbie to image processing and the image-processing algorithm is a black-box for me so I just need the array of ints that I can pass to and from this algorithm.

One thing that I am sure of is that this algorithm returns the same number of array elements that it takes as input - i.e. both input and output arrays represent the same number of image pixels.

Thanks for your help in advance.

Nirav Bhatt
  • 6,940
  • 5
  • 45
  • 89

1 Answers1

1

As I figured, CGBitmapContextGetData function returns a void pointer to the array, and it can be converted to any sort of array pointer. What matters is later processing of it.

Here is documentation.

Conversion to rgb565 can be done using this technique, taken from here:

R5 = ( R8 * 249 + 1014 ) >> 11;
G6 = ( G8 * 253 +  505 ) >> 10;
B5 = ( B8 * 249 + 1014 ) >> 11;
Community
  • 1
  • 1
Nirav Bhatt
  • 6,940
  • 5
  • 45
  • 89