Visual Studio Development Bookmark and Share   
 index > Visual C++ Express Edition > dynamic array sizing
 

dynamic array sizing

Hello all o fyou,

I want to change somewhat a porgram, but because of my minimal knowledge of C++ I hope someone can help.

The below program (only some parts are given) defines the size of a picture by COLS and ROWS, makes an array with that info and then a picutre is inputted.
If the cols and rows of the picture are different then the defined one, an error will be presented.
At compile time one needs to know the size of the picture

in p2p.h

/* standard picture: japan 17% comp */
#define COLS 363 /* number of columns in image */
#define ROWS 329 /* number of rows in image */

in p2p.c

/* Left and right images */
uchar imgL[ROWS][COLS];
...
pgmReadFile(fnameL, (char *) imgL, &cols, &rows);
if (cols != COLS || rows != ROWS) size_error(cols, rows);

I someway, I would like give the filename and the program then uses the cols and rows of the
actual picture to define the array. So a dynamic array definition (after compiling).

How do I do this? If you can point me some examples on this, that would be great!

Thanks for your help.

All the best,


Victor
VReijs  Saturday, December 02, 2006 9:23 PM
You could use std::vector to store your picture bits, ie:

//assume you read the image header and fill in the following variables:
int Components; //3 for rgb, 4 for rgba
int Rows;
int Cols;

//define and resize the vector like so:
std::vector<unsigned char> ImageBits;
ImageBits.resize(Components * Rows * Cols);


//you can access the first (or indeed any) bit like so:
int r = 0, c = 0, component = 0;
unsigned char bit = ImageBits[ ( r * Cols) + c + component ];

iccle  Tuesday, December 12, 2006 4:46 PM

You can use google to search for other answers

Custom Search

More Threads

• saving in c++
• The Guess Number Program
• Type.GetTypeFromProgID equivalent in C++
• MFC required for using XMLLite ? has anybody a workaround for that ?
• how to test snippets of code
• modifying control properties !!
• Visual C++ 2005 Express Edition (Problem after execusion of program)
• Use forms and build windows application?
• Tab controls
• pop up question