J
Joan
I read RAW image data from a binary file stream. I have to read just
bytes one by one and put them into a matrix of structs of unsigned
chars.
I have to use unsigned chars because their rangs go from 0 to 255. If
I use chars then a value of 129 will be -128
The problem:
infile.get(ImageDATA[j].R);
Reads only chars... Ok, it works fine with chars, but when I access to
the matrix the value is read like char... but i want rang from 0 -
255...
Help meeeeee
The source is something like that:
#include <iostream>
#include <fstream>
#include <ctime>
#include <stdlib.h>
using namespace std;
struct structRGB {
unsigned char R;
unsigned char G;
unsigned char B;
};
structRGB ImageDATA[576][720];
int main(int argc, char *argv[]) {
int i,j;
ifstream infile;
ofstream outfile;
infile.open("image.raw", ios::binary);
for(i=0; i<576; i++) {
for(j=0; j<720; j++) {
infile.get(ImageDATA[j].R);
infile.get(ImageDATA[j].G);
infile.get(ImageDATA[j].B);
}
}
infile.close();
outfile.open("copy.raw", ios::binary);
for(i=0; i<576; i++) {
for(j=0; j<720; j++) {
outfile.put(ImageDATA[j].R);
outfile.put(ImageDATA[j].G);
outfile.put(ImageDATA[j].B);
}
}
outfile.close();
system("PAUSE");
return 0;
}
bytes one by one and put them into a matrix of structs of unsigned
chars.
I have to use unsigned chars because their rangs go from 0 to 255. If
I use chars then a value of 129 will be -128
The problem:
infile.get(ImageDATA[j].R);
Reads only chars... Ok, it works fine with chars, but when I access to
the matrix the value is read like char... but i want rang from 0 -
255...
Help meeeeee
The source is something like that:
#include <iostream>
#include <fstream>
#include <ctime>
#include <stdlib.h>
using namespace std;
struct structRGB {
unsigned char R;
unsigned char G;
unsigned char B;
};
structRGB ImageDATA[576][720];
int main(int argc, char *argv[]) {
int i,j;
ifstream infile;
ofstream outfile;
infile.open("image.raw", ios::binary);
for(i=0; i<576; i++) {
for(j=0; j<720; j++) {
infile.get(ImageDATA[j].R);
infile.get(ImageDATA[j].G);
infile.get(ImageDATA[j].B);
}
}
infile.close();
outfile.open("copy.raw", ios::binary);
for(i=0; i<576; i++) {
for(j=0; j<720; j++) {
outfile.put(ImageDATA[j].R);
outfile.put(ImageDATA[j].G);
outfile.put(ImageDATA[j].B);
}
}
outfile.close();
system("PAUSE");
return 0;
}