문제

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)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top