From the course: Exploring C Libraries
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Modifying a PNG image - C Tutorial
From the course: Exploring C Libraries
Modifying a PNG image
- [Instructor] With image data from the png file located in the memory you're free to manipulate it, changing pixels in whatever way you prefer. In this code I draw an X over the sample png image, 05_05-image1.png which is included with the exercise files. At line eight I create a png pixel structure which contains the four elements of a pixel in RGBA png image data. Bytes for red, green, blue, and the alpha channel. This structure allows me to create color pixels to place in the image data in memory. At lines 27 and 28 I create two png pixel variables. One for the color black, and another for white. I also create a pointer to use when referencing the pixel data in memory pixel_ptr at line 29. After the image data is read and stored in memory manipulation begins after line 95. First I confirm the image color type, which must be RGBA or the pixel modification looks funky. If the image isn't of the RGBA…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.