0

I need to somehow open and read a picture of a map (jpg/png/bmp) into a 2d array so I can use the array to determine what terrain type is at that element/position on the map.

Looking for tut's on working with picture files (jpg/png/bmp) with c++ I have found none.

If anyone can send a useful link or help me directly I will worship said person/s and build an altar to them.

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Coder++
0

Are you trying to load the files by yourself? because if not, you could load the image with sdl then swipe the pixels from the SDL_Surface structure and store it into an array like you said.
It's really too bad you aren't working with .tga, because tga's are extremely easy to load. here's a tutorial to load a tga: link I know you can't do tga, but it'll give you an idea of how to work with images. I would use wikipedia to find the structure of a .bmp file, as they are the easiest of your list. Hope that helped

Edited by Coder++: n/a

0

@ Coder Okay thanks I will look at that bmp link now.


I wrote this (nicked it) to open and read the file but
I don't know if the picture is read by rows or columns.
If anyone know's that would be fantastic.

void Generate::rm()
{
std::ifstream fs("c:\\PITW\\map.png", std::ios::in|std::ios::binary);

if (!fs) {
// failed to open file - do something about it
std::cerr << "unable to open image";
return;
}

char c;
while ( fs.get( c ) )
{
std::cerr << " " << c << " ";
}

fs.close();
}

(how to use the code tags)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.