עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

טעינת קובץ BMP בC++

Featured Replies

פורסם

אני מנסה לטעון קובץ BMP בC++ הטעינה הולכת מצוין הבעיה שאני סוגר את התוכנה אני מקבל הודעה

Debug Error!

Program:..

HEAP CORRUPTION DETCTED

ועוד כמה מילים(אני כתבתי את הקוד לטעינת BMP) מה יכולה להיות הבעיה וגילתעי שברגע שאני הופך את המשתנה ללא גלובלי אז הבעיה נעלמת

שאלה 2:

אם אני טוען קובץ BMP 8 ביט אז התמונה מתעוותת למה?

פורסם

השגיאה אומרת שיש לך איפשהו דריכת זכרון בקוד שלך.

(קצת קשה לדעת מה בדיוק קורה שם בלי לראות את הקוד עצמו, כמובן...)

פורסם
  • מחבר

אין לי דריכת זיכרון בגלל שאני מקבל את ההודעה שהתכנית נסגרת הנה הקוד:



bool CTextureData2D::loadBMP(char *szFilename)
{
FILE* pFile;

fopen_s(&pFile,szFilename,"rb");

if(pFile==NULL)
{
fclose(pFile);
return false; //cannot read file
}
BITMAPFILEHEADER header;

fread(&header,sizeof(BITMAPFILEHEADER),1,pFile);

if(header.bfType != 19778) // bitmap magic number
{
fclose(pFile);
return false;//the file format is not a bmp format
}
BITMAPINFOHEADER info;

fread(&info,sizeof(BITMAPINFOHEADER),1,pFile);

Width = info.biWidth;
Height = info.biHeight;

int numColors =1<<info.biBitCount;
RGBQUAD *colorsTable;

if(info.biBitCount == 8)
{
colorsTable = new RGBQUAD[numColors];
fread(colorsTable,sizeof(RGBQUAD),numColors,pFile);
}
int dataSize = Height*Width*(unsigned int)(info.biBitCount/8.0);
unsigned char *data;
data = new unsigned char[dataSize];
if(data==NULL)
{
fclose(pFile);
return false; // cannot allocate memory for the image
}
int dataReaded = fread(data,1,dataSize,pFile);
if(dataReaded != dataSize)
{
delete []data;
if(info.biBitCount == 8)
{
delete []colorsTable;
}
return false;
}

fclose(pFile);
long ByteWidth,Padding;

ByteWidth=Padding=(int)((float)Width*info.biBitCount/8.0f);

while(Padding%4!=0)
Padding++;
if(info.biBitCount == 24)
{
DWORD diff;
int offset;
diff = (Height)*ByteWidth;
pixelData = new BYTE[diff];
if(pixelData==NULL)
{
delete []colorsTable;
delete []data;
return false;
}
offset = Padding - ByteWidth;
if(Height>0)
{
for(int i=0;i<dataSize;i+=3)
{
if((i+1)%Padding==0)
{
i+= offset;
}
pixelData[i+2] = data[i];
pixelData[i+1] = data[i+1];
pixelData[i] = data[i+2];
}
}
else
{
int j=dataSize-3;
for(int i=0;i<dataSize;i+=3)
{
if((i+1)%Padding==0)
i+= offset;
pixelData[j+2] = data[i];
pixelData[j+1] = data[i+1];
pixelData[j] = data[i+2];
j-=3;
}
}


}
else if(info.biBitCount == 8)
{
int offset,diff;
diff = Height*Width*3;
pixelData = new BYTE[diff];
if(pixelData == NULL)
{
delete[] pixelData;
delete[] colorsTable;
return false;
}
offset = Padding-ByteWidth;
if(Height>0)
{
int j=0;
for(int i=0;i<dataSize*3;i+=3)
{
if((i+1)%Padding==0)
i+= offset;
pixelData[i] = colorsTable[data[j]].rgbRed;
pixelData[i+1] = colorsTable[data[j]].rgbGreen;
pixelData[i+2] = colorsTable[data[j]].rgbBlue;
j++;
}
}
else
{
int j=dataSize-1;
for(int i=0;i<dataSize*3;i+=3)
{
if((i+1)%Padding==0)
i+= offset;
pixelData[i] = colorsTable[data[j]].rgbRed;
pixelData[i+1] = colorsTable[data[j]].rgbGreen;
pixelData[i+2] = colorsTable[data[j]].rgbBlue;
j--;
}
}
delete[] colorsTable;
}
//adding converting code
delete []data;
return true;
}

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.