Hi all, i'm working on some exercises which i have to load data from Image library. I write a load function and it work fine except when the number of images in the library becomes large.
At this moment, the limited number if around 700 images. When the number reaches to a larger number, there will be error like this
http://img248.imageshack.us/f/error1gv.png/
Belove is my function:
void Image::load_Image_From_BMP()
{
FILE *ImageFile;
if (FAILED(fopen_s(&ImageFile,fileLink,"rb")))
{
MessageBox(NULL,L"File doesn't exist",L"ImageLoader.exe",MB_OK);
return;
}
fread(&bmfh,sizeof(BITMAPFILEHEADER),1,ImageFile);
fread(&bmih,sizeof(BITMAPINFOHEADER),1,ImageFile);
dataR = (unsigned char**)malloc(sizeof(unsigned char*)* bmih.biHeight);
dataG = (unsigned char**)malloc(sizeof(unsigned char*)* bmih.biHeight);
dataB = (unsigned char**)malloc(sizeof(unsigned char*)* bmih.biHeight);
dataA = (unsigned char**)malloc(sizeof(unsigned char*)* bmih.biHeight);
for (int i = 0; i < bmih.biHeight; i++)
{
dataR[i] = (unsigned char*)malloc(sizeof(unsigned char) * bmih.biWidth);
dataG[i] = (unsigned char*)malloc(sizeof(unsigned char) * bmih.biWidth);
dataB[i] = (unsigned char*)malloc(sizeof(unsigned char) * bmih.biWidth);
dataA[i] = (unsigned char*)malloc(sizeof(unsigned char) * bmih.biWidth);
}
for (int row = 0; row < bmih.biHeight; row++)
{
for (int colum = 0; colum < bmih.biWidth; colum++)
{
theta[row][colum] = 0.0f;
r[row][colum] = 0.0f;
}
}
if (bmih.biBitCount == 24)
{
for (int row = 0; row < bmih.biHeight; row++)
{
for (int columm = 0; columm < bmih.biWidth; columm++)
{
fread(&dataR[row][columm],sizeof(unsigned char),1,ImageFile);
fread(&dataG[row][columm],sizeof(unsigned char),1,ImageFile);
fread(&dataB[row][columm],sizeof(unsigned char),1,ImageFile);
}
}
}
else if (bmih.biBitCount == 32)
{
for (int row = 0; row < bmih.biHeight; row++)
{
for (int columm = 0; columm < bmih.biWidth; columm++)
{
fread(&dataR[row][columm],sizeof(unsigned char),1,ImageFile);
fread(&dataG[row][columm],sizeof(unsigned char),1,ImageFile);
fread(&dataB[row][columm],sizeof(unsigned char),1,ImageFile);
fread(&dataA[row][columm],sizeof(unsigned char),1,ImageFile);
}
}
}
fclose(ImageFile);
}
and if i use the function like this, error will happen if the number_of_image becomes large (for example 800 images)
for (int i=0; i < number_of_image; i++)
{
load_Image_From_BMP(fileLink[i]);
}