I want to create a class from a file which
1) has parameters width and height.
2) Stores pixel data in dynamically allocated 2-dimensional array
3)By default all pixel colours are black (red, green and blue
values equal to 0).
This is the file
image-statement, BMP-file format, 300 300- Width Height of file
Colour-statement, 255-red, 0- green, 0-blue
draw-statement, Polygon-shape, 3-no. of vertices, 10 10-x1 y1, 10 90-x2 y2, 90 10- x3 y3
............
This is what i ahve written so far
[code=cpp]
class image
{
friend std::ostream &operator << (std::ostream &output, void writeBitmap() )
private:
int width, height
public:
inline image(int X = 0, int Y = 0): width(X), height(Y){}
inline image(){}
inline void getpixel()
inline void setpixel()
int **pixels(int rows, int cols)// dyanmiccally allocated array
{
pixel = new int * [rows];
for(int i=0; i< rows; i++)
matrix[i] = new int [cols];
return pixel;
}
}
using namespace std;
void image:getpixel( )
{
string line[i];
ifstream inFile("example .vec"); // opens the file
if (inFile) //Verify Open and reads from file
{
for(int i=0; !inFile.eof(); i++)
inFile >> string[i];// read into an array( but has to be 2D instead
inFile.close();
}
[/code]
So i need to know how to read the file into a 2D array where the pixel data x1 y1, x2 y2 ,..... goes into the 2D array and seperate the other parameter (width, height) in some other variables.
1) has parameters width and height.
2) Stores pixel data in dynamically allocated 2-dimensional array
3)By default all pixel colours are black (red, green and blue
values equal to 0).
This is the file
Code:
image BMP 300 300 colour <255 0 0> draw Polygon 3 <10 10> <10 90> <90 10> colour <0 255 0> draw Polygon 3 <110 110> <110 190> <190 110> colour <0 0 255> draw Polygon 3 <210 210> <210 290> <290 210>
Colour-statement, 255-red, 0- green, 0-blue
draw-statement, Polygon-shape, 3-no. of vertices, 10 10-x1 y1, 10 90-x2 y2, 90 10- x3 y3
............
This is what i ahve written so far
[code=cpp]
class image
{
friend std::ostream &operator << (std::ostream &output, void writeBitmap() )
private:
int width, height
public:
inline image(int X = 0, int Y = 0): width(X), height(Y){}
inline image(){}
inline void getpixel()
inline void setpixel()
int **pixels(int rows, int cols)// dyanmiccally allocated array
{
pixel = new int * [rows];
for(int i=0; i< rows; i++)
matrix[i] = new int [cols];
return pixel;
}
}
using namespace std;
void image:getpixel( )
{
string line[i];
ifstream inFile("example .vec"); // opens the file
if (inFile) //Verify Open and reads from file
{
for(int i=0; !inFile.eof(); i++)
inFile >> string[i];// read into an array( but has to be 2D instead
inFile.close();
}
[/code]
So i need to know how to read the file into a 2D array where the pixel data x1 y1, x2 y2 ,..... goes into the 2D array and seperate the other parameter (width, height) in some other variables.
Comment