int preprocessing(char strFile[],IMAGEDATA imagedata,PIXEL **imagepixel,long *wid,long *hei)
{
FILE *fpi;
imagedata= NULL;//动态分配存储原图片的像素信息的二维数组
long *width,*height;//新定义一个像素结构体二维数组
width=wid;height=hei;
fpi=fopen(strFile,"rb");
if(fpi != NULL){
//先读取文件类型
WORD bfType;
fread(&bfType,1,sizeof(WORD),fpi);
if(0x4d42!=bfType)
{
cout<<"the file is not a bmp file!"<<endl;
return NULL;
}
//读取bmp文件的文件头和信息头
fread(&strHead,1,sizeof(tagBITMAPFILEHEADER),fpi);
showBmpHead(strHead);//显示文件头
fread(&strInfo,1,sizeof(tagBITMAPINFOHEADER),fpi);
showBmpInforHead(strInfo);//显示文件信息头
//读取调色板
for(unsigned int nCounti=0;nCounti<strInfo.biClrUsed;nCounti++)
{
fread((char *)&(strPla[nCounti].rgbBlue),1,sizeof(BYTE),fpi);
fread((char *)&(strPla[nCounti].rgbGreen),1,sizeof(BYTE),fpi);
fread((char *)&(strPla[nCounti].rgbRed),1,sizeof(BYTE),fpi);
fread((char *)&(strPla[nCounti].rgbReserved),1,sizeof(BYTE),fpi);
}
width = &strInfo.biWidth;
height = &strInfo.biHeight;
//图像每一行的字节数必须是4的整数倍
*width = ((*width) * sizeof(IMAGEDATA) + 3) / 4 * 4;
*wid=*width;
*hei=*height;
imagedata = (IMAGEDATA)malloc((*width) * (*height) * sizeof(IMAGEDATA));
imagepixel=(PIXEL**)malloc(sizeof(PIXEL*)*(*height));
for(int w=0;w<(*height);w++)
{
imagepixel[w]=(PIXEL*)malloc(sizeof(PIXEL*)*(*width));
}
//初始化原始图片的像素数组以及新构造的像素数组
for(int i = 0;i < (*height);++i)
{
for(int j = 0;j < (*width);++j)
{
(*(imagedata + i * (*width )+ j)).blue = 0;
imagepixel[i][j].blue = 0;//系统提示这一句;
imagepixel[i][j].tag = 0;
imagepixel[i][j].t = i * (*width )+ j;
}
}
//fseek(fpi,54,SEEK_SET);
//读出图片的像素数据
fread(imagedata,sizeof(struct tagIMAGEDATA) (*width),(*height),fpi);
fclose(fpi);
for(i = 0;i <(*height);++i)
{
for(int j = 0;j < (*width);++j)
{
imagepixel[i][j].blue=((imagedata + i * (*width) + j)).blue;
}
}
processingpixel(imagedata,imagepixel,width,height);//对像素操作
}
else
{
cout<<"file open error!"<<endl;
return NULL;
}
fclose(fpi);
afterprocessing(imagedata,width,height);
return 0;
}
C++,为一个二维数组赋值,为什么到一半就停止了?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
0条回答 默认 最新
悬赏问题
- ¥20 怎么在stm32门禁成品上增加记录功能
- ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
- ¥50 NT4.0系统 STOP:0X0000007B
- ¥15 想问一下stata17中这段代码哪里有问题呀
- ¥15 flink cdc无法实时同步mysql数据
- ¥100 有人会搭建GPT-J-6B框架吗?有偿
- ¥15 求差集那个函数有问题,有无佬可以解决
- ¥15 【提问】基于Invest的水源涵养
- ¥20 微信网友居然可以通过vx号找到我绑的手机号
- ¥15 解riccati方程组