Jump to content
  • Advertisement
Sign in to follow this  
matthewsweda

Reading an image file

This topic is 2849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!