VC6.0图形处理10--腐蚀膨胀

void CBMPViewerDoc::OnMenuitem32799() //图像的腐蚀
{


//自定义3*3的矩阵作为检验的结构
// TODO: Add your command handler code here


int linewidth;
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;


unsigned char *lpDest;
unsigned char *lpScr;



HLOCAL hTemp;
hTemp = LocalAlloc(LHND ,linewidth * bi.biHeight );

LPSTR lpTemp;
lpTemp = (char*)LocalLock(hTemp);//以上四句分配一块与源图像数据大小一致的内存块,并返回指针lpTemp
//暂时存储新建的图片数据,完成后,将数据copy给原数据区

int pixel;
// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight ; i++)
{
for(int j = 0 ; j< bi.biWidth ; j++)
{
    lpDest = (unsigned  char *)lpTemp+linewidth*(bi.biHeight - i -1 ) + j ;
if((i == 0 ) || (j ==0) || (i == bi.biHeight) || (j == bi.biWidth) ){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - i -1) + j;
*lpDest = *lpScr;




else
{

//lpDest = (unsigned  char *)lpTemp+linewidth*(bi.biHeight - i -1 ) + j ;
*lpDest = 0;

for(int s = -1 ; s<=1; s++)
{
for(int t = -1; t <= 1;t++)
{
lpScr = (unsigned char *)lpBuf + linewidth*(bi.biHeight - i-1 + s) + j + t;
              
pixel = *lpScr;
if(pixel == 255)
{


*lpDest = 255;
}


}


}
   

}

}

}

memcpy(lpBuf , lpTemp, linewidth*bi.biHeight); //新图像数据copy给源数据
// Invalidata(TRUE);
UpdateAllViews(NULL,0,NULL);

}


void CBMPViewerDoc::OnMenuitem32800() //图像的膨胀
{

//自定义结构
// TODO: Add your command handler code here

int linewidth;
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;

unsigned char *lpDest;
unsigned char *lpScr;


HLOCAL hTemp;
hTemp = LocalAlloc(LHND ,linewidth * bi.biHeight );

LPSTR lpTemp;
lpTemp = (char*)LocalLock(hTemp);//以上四句分配一块与源图像数据大小一致的内存块,并返回指针lpTemp
//暂时存储新建的图片数据,完成后,将数据copy给原数据区

int pixel;
// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight ; i++)
{
for(int j = 0 ; j< bi.biWidth ; j++)
{
lpDest = (unsigned  char *)lpTemp+linewidth*(bi.biHeight - i -1 ) + j ;
if((i == 0 ) || (j ==0) || (i == bi.biHeight) || (j == bi.biWidth) ){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - i -1) + j;
*lpDest = *lpScr;



else
{

//lpDest = (unsigned  char *)lpTemp+linewidth*(bi.biHeight - i -1 ) + j ;
*lpDest = 255;




for(int s = 0 ; s<=1; s++)
{
for(int t = 0; t <= 1;t++)
{
lpScr = (unsigned char *)lpBuf + linewidth*(bi.biHeight - i-1 + s) + j + t;

pixel = *lpScr;
if(pixel == 0)
{
*lpDest = 0;
}

}

}


}

}

}

memcpy(lpBuf , lpTemp, linewidth*bi.biHeight); //新图像数据copy给源数据
// Invalidata(TRUE);
UpdateAllViews(NULL,0,NULL);

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值