C Codes
Beginners
C on Unix
Code Snippets
Data Structures
File Operations
Games Graphics
Gnu-Linux
Hardware
Mathematics
Miscellaneous
Small Programs
Sorting
C > Small Programs sample source codes
Get color and coordinates for each pixel
Get color and coordinates for each pixel #include <stdio.h> #include <gd.h> int main(int argc, char *argv[]) { FILE *fp = {0}; gdImagePtr img; int x = 0; int y = 0; int width = 0; int height = 0; if(argc != 2) { fprintf(stderr, "Usage: gixel image.png\n"); return 1; } fp = fopen(argv[1], "rb"); if(fp == NULL) { fprintf(stderr, "Error - fopen(%s)\n", argv[1]); return 1; } img = gdImageCreateFromPng(fp); fclose(fp); width = gdImageSX(img); height = gdImageSY(img); for(x = 0; x < width; x++) for(y = 0; y < height; y++) printf("%d,%d:%X\n", x, y, gdImageGetPixel(img, x, y)); gdImageDestroy(img); return 0; }
Privacy Policy
|
Link to Us
|
Links