Home > Back-end >  There was a pile of broken program is running
There was a pile of broken program is running

Time:05-18

Bengbu, write their own BMP file to read and write operation error, error on the statements in the fopen, below is the code:
Int Laplace [3] [3]=
{
{1, 1, 1},
{1, 8, 1},
{1, 1, 1}
};

Int main ()
{

Char * fpath="E: \ \ pic_test \ \ pic_test_out \ \ 3. BMP";
Char * fdstpath="E: \ \ pic_test \ \ pic_test_out \ \ 7. BMP";

BMP bitmap, bitmapout;
BmpRead (bitmap, fpath);
PicGrad (bitmap, Laplace, bitmapout);
BmpWrite (bitmapout fdstpath);
The delete [] bitmap. The data;
The delete [] bitmapout. Data;
return 0;
}

Void bmpWrite (BMP bitmap, const char * bmpPath)
{
The FILE * FILE=fopen (bmpPath, "wb");
If (NULL==file)
return;
Int iByteLength=0;
Int colorsize=0;
If (==8 bitmap. MCount)
{
IByteLength=(bitmap. MWidth + 3)/4 * 4;
Colorsize=1024;
}
Else if (==24 bitmap. MCount)
{
IByteLength=(bitmap. MWidth * 3 + 3)/4 * 4;
}
The else
{
IByteLength=(bitmap. The bitmap mWidth *. MCount/3 + 3)/4 * 4;
}
BITMAPFILEHEADER BMPHD;
BMPHD. BfType=0 x4d42;
BMPHD. BfOffBits=sizeof (BITMAPINFOHEADER) + sizeof (BITMAPFILEHEADER) + colorsize;
BMPHD. BfSize=BMPHD. BfOffBits + iByteLength * bitmap mHeight;
BMPHD. BfReserved1=0;
BMPHD. BfReserved2=0;

BITMAPINFOHEADER bmpin;
Bmpin. BiBitCount=bitmap. MCount;
Bmpin. BiClrImportant=0;
Bmpin. BiClrUsed=0;
Bmpin. BiCompression=0;
Bmpin. BiHeight=bitmap. MHeight;
Bmpin. BiPlanes=1;
Bmpin. BiSize=sizeof (BITMAPINFOHEADER);
Bmpin. BiSizeImage=0;
Bmpin. BiWidth=bitmap. MWidth;
Bmpin. BiXPelsPerMeter=0;
Bmpin. BiYPelsPerMeter=0;

Fwrite (& amp; BMPHD, sizeof (BITMAPFILEHEADER), 1, file);
Fwrite (& amp; Bmpin, sizeof (BITMAPINFOHEADER), 1, file);

If (bitmap. MCount==8)
{
Unsigned char uchPalette [256 * 4];
For (int j=0; J & lt; 256; J++)
{
UchPalette [j * 4]=(unsigned char) j;
UchPalette [j * 4 + 1)=(unsigned char) j;
UchPalette [j * 4 + 2]=(unsigned char) j;
UchPalette [j * 4 + 3]=0;
}
Fwrite (uchPalette, sizeof (RGBQUAD), 256, file).
}

Fwrite (bitmap data, iByteLength, bitmap mHeight, file).
The fclose (file);
}

Error in bmpwrite () function of the first line... Into the function of internal until the place out of the question:


Not sure where the problem is, beg greatly answer!!

CodePudding user response:

Has been solved, but no satisfaction and does not return, don't want to waste fraction, to some people I casually scattered

CodePudding user response:

Ceng points to the [face] emoji: 019 PNG [/face]

CodePudding user response:

Should be the file path problem, we can through the strerror (errno); Look at the fopen to open the failure reason,
  • Related