VC++大神帮我解释一下这个程序
voidCDib::SaltNoise(){intwidth,height;DWORDNumberOfPixels;intx,y;doublefx,fy;CNoiseDl...
voidCDib::SaltNoise()
{
int width,height;
DWORD NumberOfPixels;
int x,y;
double fx,fy;
CNoiseDlg dlg;
width=GetDibWidth();
height=GetDibHeight();
NumberOfPixels=DWORD((width*height)/3);
DWORD noisenumber;
if(dlg.DoModal()==IDOK)
{
noisenumber=dlg.m_NoisePercentage*NumberOfPixels/100;
BYTE*PDIBDATA=(BYTE*)::GlobalLock((HGLOBAL) m_pDIBData);
for(DWORDi=1;i<noisenumber;i++)
{
fx=(double)rand()/(RAND_MAX+1);
fy=(double)rand()/(RAND_MAX+1);
x=int(fx*width);
y=int(fy*height);
int position;
position=width*3*y+x*3;
if(rand()>RAND_MAX/2)
{
PDIBDATA[position]=255;
PDIBDATA[position+1]=255;
PDIBDATA[position+2]=255;
}
else
{
PDIBDATA[position]=0;
PDIBDATA[position+1]=0;
PDIBDATA[position+2]=0;
}
}
::GlobalUnlock((HGLOBAL)m_pDIBData);
}
} 展开
{
int width,height;
DWORD NumberOfPixels;
int x,y;
double fx,fy;
CNoiseDlg dlg;
width=GetDibWidth();
height=GetDibHeight();
NumberOfPixels=DWORD((width*height)/3);
DWORD noisenumber;
if(dlg.DoModal()==IDOK)
{
noisenumber=dlg.m_NoisePercentage*NumberOfPixels/100;
BYTE*PDIBDATA=(BYTE*)::GlobalLock((HGLOBAL) m_pDIBData);
for(DWORDi=1;i<noisenumber;i++)
{
fx=(double)rand()/(RAND_MAX+1);
fy=(double)rand()/(RAND_MAX+1);
x=int(fx*width);
y=int(fy*height);
int position;
position=width*3*y+x*3;
if(rand()>RAND_MAX/2)
{
PDIBDATA[position]=255;
PDIBDATA[position+1]=255;
PDIBDATA[position+2]=255;
}
else
{
PDIBDATA[position]=0;
PDIBDATA[position+1]=0;
PDIBDATA[position+2]=0;
}
}
::GlobalUnlock((HGLOBAL)m_pDIBData);
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询