Image Reading

Hey, I'm trying to read a BMP file and write it to a new BMP.
The new file opens with paint and has the right dimensions, but is completely
blank whitespace and none of the random colors I put in the original file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
ofstream superImage;
ifstream megaImage;
char* buffer;
int size;
superImage.open("superImage.bmp", fstream::out);
if(superImage.is_open())
{
	cout << "File is good";
}
megaImage.open("NewImage.bmp", fstream::in);
if(megaImage.is_open())
{
	cout << "File is good";
}
size = megaImage.tellg();
buffer = new char [size];
megaImage.seekg(0, ios::beg);
megaImage.read(buffer, size);
superImage.write(buffer, size);
delete[] buffer;
superImage.close();
megaImage.close();


Any tips, I'm a bit of a noob.
Last edited on
Okay, i realized why it was blank, but there's still something wrong, the output image is completely different. It has 80% of the canvas in a shade of grey and color in the bottom that resemble, but is still completely different, from the original.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
ofstream superImage;
ifstream megaImage;
char* buffer;
int size;
superImage.open("superImage.bmp", fstream::out);
if(superImage.is_open())
{
	cout << "File is good";
}
megaImage.open("NewImage.bmp", fstream::in|ios::ate);
if(megaImage.is_open())
{
	cout << "File is good";
}
size = megaImage.tellg();
buffer = new char [size];
megaImage.seekg(0, ios::beg);
megaImage.read(buffer, size);
superImage.write(buffer, size);
delete[] buffer;
superImage.close();
megaImage.close();


Update:: while this doesn't solve the problem. i figured out part of the cause. it was because you can only output 16 color bitmaps this way. anyone know a work around?
Last edited on
Topic archived. No new replies allowed.