0

Hello I'm making an application that reads a series of values from a text file and then converts it to a bitmap image.

Currently, I'm using arrays, but, deciding on a particular length is annoying.

I have been reading a few tutorials and i've read a lot about using vectors, which, I am happy to do so. But my question is this:

Can I use a vector like this:

vector<pixel> myImage;

Each binary digit in the text file represents a pixel in the Bitmap image?

Thanks :)

2
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by firstPerson
0

If you want to read the file into a vector, then you can represent each pixel as a char or int. For example you can have something like so, std::vector<char> pixels; and read from file into that vector. For example:

std::vector<char> pixels;
ifstream fileInput("imagefile.txt");
//read from file into vector
std::copy( std::istream_iterator<char>(fileInput), 
                std::istream_iterator<char>(),
                std::back_inserter(pixels));

for(int i = 0; i < pixels.size(); ++i){
  cout << pixels[i];
}
0

Hey thank you for your reply :)

I'm using something simular to that.

Just out of interest though: Vectors OR arrays for image manipulation?

Personally I want to use Vectors and only really use arrays when needed.

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.