I loaded a 24-bit uncompressed Bitmap into a 2D array of R,G,B unsigned chars, and then saved it again, I use file streams in binary modes to ensure no auto formatting occur, and the header is exported just as imported as whole...Padding is not required since i use images which are multiples of 4 in width.
Yet the output have the attached issue, some kind of...deformation
Note : I tried both FILE and fstream in binary modes and all gave that output Another thing is that on checking the output with a hex editor i found that it has a very repeated value of "CD" which appears to be some kind of corruption.
Update : Source code:
#include <fstream>
#include <iostream>
#pragma pack(2)
using namespace std;
struct RGB
{
unsigned char R,G,B;
};
int main()
{
ifstream f("Picture.bmp",ios::in|ios::binary);
unsigned char Header[54];
f.read(reinterpret_cast <char*> (Header),54);
int W=*(int*) (&Header[18]);
int H=*(int*) (&Header[22]);
RGB**Pic=new RGB*[H];
for (int i=0;i < H;i++)
{
Pic[i]=new RGB[W];
for (int i2=0;i2<W;i2++)
{
f>>Pic[i][i2].R;
f>>Pic[i][i2].B;
f>>Pic[i][i2].G;
}
}
ofstream save("Output.bmp",ios::out|ios::binary);
save.write(reinterpret_cast<char*>(&Header),54);
for (int i=0;i < H;i++)
{
for (int i2=0;i2<W;i2++)
{
save<<Pic[i][i2].R;
save<<Pic[i][i2].B;
save<<Pic[i][i2].G;
}
}
return 0;
}
Thanks in advance.