![]() |
| | #1 |
| Registered User Join Date: Jan 2010
Posts: 3
| getting pixel data from image using libpng But I cannot seem to figure out how to read/interpret the pixel data using libpng. Can someone help me find out how I would read a png image and read each pixel's data into an array? |
| mamacken is offline | |
| | #2 |
| Registered User Join Date: Sep 2006
Posts: 3,148
| We don't work quite that way. YOU show US what you've done to try to solve the problem, and where you're stuck - with code, preferably. When we see code that you're working with, we can be specific. Without it, we can't be specific. Is your file a PNG file? Did you read up on it's format? Did you look at it's contents with a Hex Editor? How did you open the file? What kind of variables did you use? See what I mean? |
| Adak is offline | |
| | #3 |
| Registered User Join Date: Jan 2010
Posts: 3
| I don't really have code to show you that would be of any help. But I can be more specific with the nature of my problem. My program reads in a PNG file and I can fetch it's width and height from the info structure. I also know how to read each row into an array of type png_bytep. I have no idea how I am supposed to access the individual color components of each pixel from the byte array though. I apologize for my vague description initially, I am just new to this particular library, and it's common usage is apparently quite different than what I am attemping to use it for. |
| mamacken is offline | |
| | #4 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,768
| If the pixels are 24-bit RGB, then the data is composed of interleaved and repeating R, G, and B samples. R comes first, then G, then B. Code: unsigned char *red = (unsigned char *)ptrToRow[ Y ] + 3 * X; unsigned char *green = (unsigned char *)ptrToRow[ Y ] + 3 * X + 1; unsigned char *blue = (unsigned char *)ptrToRow[ Y ] + 3 * X + 2;
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot |
| brewbuck is offline | |
| | #5 |
| Registered User Join Date: Jan 2010
Posts: 3
| Thank you very much. |
| mamacken is offline | |
| | #6 |
| Registered User Join Date: Aug 2006 Location: Liverpool UK
Posts: 452
| |
| rogster001 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| xor linked list | adramalech | C Programming | 23 | 10-14-2008 10:13 AM |
| Abnormal Program Termination when executed from C:\Program Files\... | m37h0d | Windows Programming | 48 | 09-26-2008 03:45 AM |
| Image rotation - doesn't always work | ulillillia | C Programming | 12 | 05-03-2007 12:46 PM |
| [question]Analyzing data in a two-dimensional array | burbose | C Programming | 2 | 06-13-2005 07:31 AM |
| Program Crashing | Pressure | C Programming | 3 | 04-18-2005 10:28 PM |