写了一个处理图像的程序,编译通过。运行时,老是出错。0xc0000005 access violation 。调试运行指向红色代码。BOOL Matrix(CDib *pDib,UINT i, UINT j)
{
BYTE * lpSrc; //指向源图像的指针
LONG lWidth; //图像的宽度和
LONG lHeight; //高度 if (pDib->IsEmpty ())
{
AfxMessageBox("请先读入图像");
return FALSE;
}
lWidth=pDib->m_lpBMIH ->biWidth ;
lHeight=pDib->m_lpBMIH ->biHeight ;
LPBYTE lpDIBBits=pDib->m_lpImage ; //DIB位图数据块地址 LONG SWidth, SHeight;
SWidth=lWidth/i; //每个方格的宽度
SHeight=lHeight/j; //每个方格的高度 int a=0;
int b=0;
for(int m=0;m<lHeight; m+=SHeight)
for(int n=0;n<lWidth*3;n+=SWidth)
{
lpDIBBits=lpDIBBits+m*SHeight+n*SWidth;
//扫描划分的小方格的像素
for(int h=0;h<SHeight;h++)
for(int w=0;w<SWidth*3;w+=3)
{
lpSrc=(unsigned char *)lpDIBBits+lWidth*3*w+h; //需改
if((*lpSrc)==0)
{
a=a+1;
}
else if(*lpSrc==255)
{
b=b+1;
}
}
//方格中0值的像素多,则置0;否则,置255
if(a>b)
{
for(int h=0;h<SHeight;h++)
for(int w=0;w<SWidth*3;w+=3)
{
lpSrc=(unsigned char *)lpDIBBits+lWidth*3*w+h;
*lpSrc=0;
}
}
else
{
for(int h=0;h<SHeight;h++)
for(int w=0;w<SWidth*3;w+=3)
{
lpSrc=(unsigned char *)lpDIBBits+lWidth*3*w+h;
*lpSrc=255;
}
} }
return TRUE;
}void CImageView::OnMatrix() //菜单响应函数
{
// TODO: Add your command handler code here
CImageDoc* pDoc;
pDoc=GetDocument();
Matrix(pDoc->m_pImage,100,100); pDoc->UpdateAllViews (NULL);}
{
BYTE * lpSrc; //指向源图像的指针
LONG lWidth; //图像的宽度和
LONG lHeight; //高度 if (pDib->IsEmpty ())
{
AfxMessageBox("请先读入图像");
return FALSE;
}
lWidth=pDib->m_lpBMIH ->biWidth ;
lHeight=pDib->m_lpBMIH ->biHeight ;
LPBYTE lpDIBBits=pDib->m_lpImage ; //DIB位图数据块地址 LONG SWidth, SHeight;
SWidth=lWidth/i; //每个方格的宽度
SHeight=lHeight/j; //每个方格的高度 int a=0;
int b=0;
for(int m=0;m<lHeight; m+=SHeight)
for(int n=0;n<lWidth*3;n+=SWidth)
{
lpDIBBits=lpDIBBits+m*SHeight+n*SWidth;
//扫描划分的小方格的像素
for(int h=0;h<SHeight;h++)
for(int w=0;w<SWidth*3;w+=3)
{
lpSrc=(unsigned char *)lpDIBBits+lWidth*3*w+h; //需改
if((*lpSrc)==0)
{
a=a+1;
}
else if(*lpSrc==255)
{
b=b+1;
}
}
//方格中0值的像素多,则置0;否则,置255
if(a>b)
{
for(int h=0;h<SHeight;h++)
for(int w=0;w<SWidth*3;w+=3)
{
lpSrc=(unsigned char *)lpDIBBits+lWidth*3*w+h;
*lpSrc=0;
}
}
else
{
for(int h=0;h<SHeight;h++)
for(int w=0;w<SWidth*3;w+=3)
{
lpSrc=(unsigned char *)lpDIBBits+lWidth*3*w+h;
*lpSrc=255;
}
} }
return TRUE;
}void CImageView::OnMatrix() //菜单响应函数
{
// TODO: Add your command handler code here
CImageDoc* pDoc;
pDoc=GetDocument();
Matrix(pDoc->m_pImage,100,100); pDoc->UpdateAllViews (NULL);}
解决方案 »
- 数据库驱动程序在哪里进行设置
- VC6.0编译的问题
- 急救!对话框上不能放置ActiveX控件是咋回事呀?
- 如果在SDK中设置窗口或是Control的字体?
- 请问在VC程序中TRACE宏怎么用啊?
- 如何在网页中从msn导入电子邮件?100分奉上!
- ★请问CCmdTarget的OnCmdMsg函数是怎么被触发的~~~~~大虾帮忙,谢谢~
- 请求援助:怎么读取XML文件中的属性值?如果属性定义在DTD中,可以读取吗?还有如何修改某个借点的值?
- 我在对子对话框进行重画时,关闭子对话框连主对话框也关闭了.请问为什么?
- 请教关于键盘响应的问题
- sdl设置声音freq只有SDL_OpenAudio一个接口,如果我在播放声音时想动态设置freq(比如快进),不支持这样做吗
- 请问哪有“Visual C++数字图像与图形处理”光盘源码?
我的QQ,哪位高手帮忙看看程序。可把源程序发给您