问题描述:

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.

网友答案:

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.

网友答案:

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)

相关阅读:
Top