views:

230

answers:

2

How would I go about converting the pixels in an image (.png file) to an integer array, where each pixel is converted to its ARGB integer equivalent? Not a 2D integer array by the way, a 1D one (where access is through array[row*width+col]).

Thanks.

A: 

Unless you are doing it for interest and learning, I would recommend you do use a third party library, for example ImageMagick.
This will save you time (and avoid bugs)

hamishmcn
Any feedback on why the downvote?
hamishmcn
+1  A: 

Once you have read image data to some buffer, ordinary cast should do the trick:

GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file ("image.png", NULL);
unsigned char *pixels = gdk_pixbuf_get_pixels (pixbuf);
int *array = reinterpret_cast<int*>(pixels);

Example uses GdkPixbuf library, but other libraries should be similar.

el.pescado