Reading an image file

Started by
6 comments, last by matthewsweda 13 years, 5 months ago
Hello Forum!
I am trying to create a program that reads image files, (of the most common type, .jpg, .bmp, .tga, etc.), and then outputs a .txt file with the Y location of the topmost Black pixel. Why is this helpful? Once I have the text file I could then read the file (most likely using ifstream) and fill an array (the size of the x distance of the current level) with the Y coordinates. After the array is filled the final step is to compare the player's Y position against Array[Player.x] and check if the player has collided with the black pixel's coordinates. This would make it easy to paint a background and use a black color only for the edge (...or where I want the player to stand)
I have the dialog box and the browser already set up, the only problem is what to do with the image file once I attain it. More specifically, how do I read the pixel color of the image to see what Y value I should output?
Thanks - Matt
Advertisement
Quote:
More specifically, how do I read the pixel color of the image to see what Y value I should output?


The answer to this is different for every filetype, some of which have quite complex decompression which is not trivial to perform. I'd suggest you get yourself an image loading library (DevIL comes to mind as a popular one), and use that. If you plan to write image loading code yourself for all flavors of jpg, png, etc, then expect to spend a long time and have many headaches.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
I'd say, why go to the trouble of exporting a text file afterwords? just do the collisions against the image itself. It might be a tiny bit slower, but you gain the benefit of cool effects, like fully destructible terrain (just paint white on the collision image to remove collision!).
Alright,
Thanks for the swift reply!
I'll check out DevIL and other's like it.
If they don't produce the desired effect I will post on this thread again.
- Matt
Beware; if you use lossless compression (like jpeg), the topmost black pixel could stop being pure black, or another higher and less black (i.e. dark gray) pixel could become black.
Ok I decided to go with DevIL since it looks the most reliable.
Still, I don't know what to do with it!
It there any tutorial that describes exactly how to read the image data and determine what to output as my Y coordinate?
Thanks - Matt
Quote:Original post by matthewsweda
Ok I decided to go with DevIL since it looks the most reliable.
Still, I don't know what to do with it!
It there any tutorial that describes exactly how to read the image data and determine what to output as my Y coordinate?
Thanks - Matt


Did you try [google]?
Ok, you got me!
I actually did try google but I fell for the "Lazy trap"... Let's face it: it's so much more simple to have a more expirienced programmer tell you exactly what to do. It's not very profittable in the long run but it is very tempting. I'll fall back to google but if anybody has a helpful starting point that helped them when they were new to DevIL I would like to hear it!
Thanks - Matt

This topic is closed to new replies.

Advertisement