📄 carlpdlg.cpp
字号:
bmh.bfSize=nLen;
bmh.bfReserved1=0;
bmh.bfReserved2=0;
bmh.bfOffBits=54;
memcpy(lpBitmap,&bmh,sizeof(BITMAPFILEHEADER));
memcpy(lpBitmap+sizeof(BITMAPFILEHEADER),pMem,size);
LoadBitmap();
if (lpBitmap) source.SetImage(nWidth,nHeight,lpBits);
GlobalUnlock(hMem);
FileName="";
}
CloseClipboard();
}
}
void CCarLPDlg::Copy()
{
if (dest.lpBits==0) return;
OpenClipboard();
EmptyClipboard();
HGLOBAL hMem;
BYTE *pMem;
int nLen=dest.nByteWidth*dest.nHeight;
hMem=GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE,nLen+sizeof(BITMAPINFOHEADER));
pMem=(BYTE *)GlobalLock(hMem);
BITMAPINFOHEADER *bmi=(BITMAPINFOHEADER *)pMem;
bmi->biSize=sizeof(BITMAPINFOHEADER);
bmi->biWidth=nWidth;
bmi->biHeight=nHeight;
bmi->biPlanes=1;
bmi->biBitCount=24;
bmi->biCompression=BI_RGB;
bmi->biSizeImage=0;
bmi->biXPelsPerMeter=0;
bmi->biYPelsPerMeter=0;
bmi->biClrUsed=0;
bmi->biClrImportant=0;
memcpy(pMem+sizeof(BITMAPINFOHEADER),dest.lpBits,nLen);
GlobalUnlock(hMem);
SetClipboardData(CF_DIB,hMem);
CloseClipboard();
}
void CCarLPDlg::NoColor()
{
if (lpBitmap==0) return;
int x,y,p;
BYTE Point;
for(y=0;y<nHeight;y++)
{
for(x=0;x<nWidth;x++)
{
p=x*3+y*nByteWidth;//24位位图
Point=(BYTE)(0.299*(float)lpBits[p+2]+0.587*(float)lpBits[p+1]+0.114*(float)lpBits[p]+0.1);
lpBits[p+2]=Point;
lpBits[p+1]=Point;
lpBits[p]=Point;
}
}
source.SetImage(nWidth,nHeight,lpBits);
}
void CCarLPDlg::Noise(int type)
{
if (lpBitmap==0) return;
int x,y,p;
BYTE Point;
srand((unsigned)time(NULL));
if (type==0)
{
for(y=0;y<nHeight;y++)
{
for(x=0;x<nWidth;x++)
{
Point=rand()/1024;
p=x*3+y*nByteWidth;
lpBits[p+2]=lpBits[p+2]*224/256+Point;
lpBits[p+1]=lpBits[p+1]*224/256+Point;
lpBits[p]=lpBits[p]*224/256+Point;
}
}
}
else
{
for(y=0;y<nHeight;y++)
{
for(x=0;x<nWidth;x++)
{
if (rand()>31500)
{
p=x*3+y*nByteWidth;
lpBits[p+2]=0;
lpBits[p+1]=0;
lpBits[p]=0;
}
}
}
}
source.SetImage(nWidth,nHeight,lpBits);
}
void CCarLPDlg::BrightModify()
{
if (lpBitmap==0) return;
int x,y;
BYTE *lpOutput=new BYTE[nByteWidth*nHeight];
memset(lpOutput,0,nByteWidth*nHeight);
for(y=0;y<nHeight;y++)
{
for(x=0;x<nWidth*3;x++)
{
lpOutput[x+nByteWidth*y]=255-lpBits[x+nByteWidth*y];
}
}
dest.SetImage(nWidth,nHeight,lpOutput);
delete lpOutput;
}
void CCarLPDlg::Restore()
{
if (lpBackup && lpBitmap)
{
memcpy(lpBitmap,lpBackup,nLen);
source.SetImage(nWidth,nHeight,lpBits);
}
}
void BiValue1(int nWidth,int nHeight,BYTE *lpInput,BYTE *lpOutput);
void CCarLPDlg::BiValue()
{
if (lpBitmap==0) return;
BYTE *lpOutput=new BYTE[nByteWidth*nHeight];
BiValue1(nWidth,nHeight,lpBits,lpOutput);
dest.SetImage(nWidth,nHeight,lpOutput);
delete lpOutput;
}
void Sobel(int nWidth,int nHeight,BYTE *lpInput,BYTE *lpOutput,void (* Progress)(int Pos));
void Prewitte(int nWidth,int nHeight,BYTE *lpInput,BYTE *lpOutput,void (* Progress)(int Pos));
void Roberts(int nWidth,int nHeight,BYTE *lpInput,BYTE *lpOutput,void (* Progress)(int Pos));
void LoG(int nWidth,int nHeight,BYTE *lpIn,BYTE *lpOut,void (* Progress)(int Pos));
void CCarLPDlg::Edge()
{
if (lpBitmap==0) return;
CProcessDlg dlg;
dlg.Introduce="边缘提取";
dlg.Process1=Sobel;
dlg.Option1="Sobel边缘算子法";
dlg.Process2=Prewitte;
dlg.Option2="Prewitte边缘算子法";
dlg.Process3=Roberts;
dlg.Option3="Roberts边缘算子法";
dlg.Process4=LoG;
dlg.Option4="LoG边缘算子法";
dlg.pDest=&dest;
dlg.lpInput=lpBits;
dlg.nWidth=nWidth;
dlg.nHeight=nHeight;
dlg.DoModal();
}
void CCarLPDlg::SaveAs()
{
if (dest.lpBits==0) return;
CFileDialog dlg(FALSE,"bmp",FileName,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"位图文件|*.bmp||");
CFile file;
if (dlg.DoModal()==IDOK)
{
if (!file.Open(dlg.GetPathName(),CFile::modeWrite|CFile::modeCreate))
{
MessageBox("无法打开指定的文件");
return;
}
int nLen=dest.nByteWidth*dest.nHeight;
BYTE *pMem=new BYTE[nLen+sizeof(BITMAPINFOHEADER)];
BITMAPINFOHEADER *bmi=(BITMAPINFOHEADER *)pMem;
bmi->biSize=sizeof(BITMAPINFOHEADER);
bmi->biWidth=nWidth;
bmi->biHeight=nHeight;
bmi->biPlanes=1;
bmi->biBitCount=24;
bmi->biCompression=BI_RGB;
bmi->biSizeImage=0;
bmi->biXPelsPerMeter=0;
bmi->biYPelsPerMeter=0;
bmi->biClrUsed=0;
bmi->biClrImportant=0;
BITMAPFILEHEADER bmh;
bmh.bfType='B'+'M'*256;
bmh.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+nLen;
bmh.bfReserved1=0;
bmh.bfReserved2=0;
bmh.bfOffBits=54;
memcpy(pMem+sizeof(BITMAPINFOHEADER),dest.lpBits,nLen);
file.Write(&bmh,sizeof(BITMAPFILEHEADER));
file.Write(pMem,nLen+sizeof(BITMAPINFOHEADER));
file.Close();
}
}
void CCarLPDlg::PrintImages()
{
if (source.lpBits==0) return;
if (dest.lpBits && (source.nWidth!=dest.nWidth || source.nHeight!=dest.nHeight))
{
MessageBox("图像尺寸不一致,无法打印!");
return;
}
CPrintDialog dlg(FALSE);
if (dlg.DoModal()==IDOK)
{
CDC dc;
dc.Attach(dlg.m_pd.hDC);
DOCINFO di;
di.cbSize=sizeof(di);
di.fwType=0;
di.lpszDatatype=0;
di.lpszDocName="数字图像处理实验演示软件";
di.lpszOutput=0;
dc.SetMapMode(MM_LOENGLISH);
int maxWidth,maxHeight;
maxWidth=dc.GetDeviceCaps(HORZRES)-400;
maxHeight=(dc.GetDeviceCaps(VERTRES)-1000)/2;
dc.StartDoc(&di);
BITMAPINFOHEADER bmi;
bmi.biSize=sizeof(BITMAPINFOHEADER);
bmi.biWidth=nWidth;
bmi.biHeight=nHeight;
bmi.biPlanes=1;
bmi.biBitCount=24;
bmi.biCompression=BI_RGB;
bmi.biSizeImage=0;
bmi.biXPelsPerMeter=0;
bmi.biYPelsPerMeter=0;
bmi.biClrUsed=0;
bmi.biClrImportant=0;
int w=nWidth*5,h=nHeight*5,xc;
if (w>maxWidth)
{
w=maxWidth;
h=h*maxWidth/w;
}
if (h>maxHeight)
{
h=maxHeight;
w=w*maxHeight/h;
}
xc=(maxWidth-w)/2;
dc.StartPage();
StretchDIBits(dc.m_hDC,200+xc,200,w,h,0,0,nWidth,nHeight,
source.lpBits,
(BITMAPINFO *)&bmi,
DIB_RGB_COLORS,
SRCCOPY);
StretchDIBits(dc.m_hDC,200+xc,400+h,w,h,0,0,nWidth,nHeight,
dest.lpBits,
(BITMAPINFO *)&bmi,
DIB_RGB_COLORS,
SRCCOPY);
dc.EndPage();
dc.EndDoc();
}
DeleteDC(dlg.m_pd.hDC);
GlobalFree(dlg.m_pd.hDevMode);
GlobalFree(dlg.m_pd.hDevNames);
}
void PseudoColor1(int nWidth,int nHeight,BYTE *lpInput,BYTE *lpOutput,void (* Progress)(int Pos));
void PseudoColor2(int nWidth,int nHeight,BYTE *lpInput,BYTE *lpOutput,void (* Progress)(int Pos));
void CCarLPDlg::PseudoColor()
{
if (lpBitmap==0) return;
CProcessDlg dlg;
dlg.Introduce="伪彩色";
dlg.Process1=PseudoColor1;
dlg.Option1="医学伪彩色处理";
dlg.Process2=PseudoColor2;
dlg.Option2="遥感伪彩色处理";
dlg.pDest=&dest;
dlg.lpInput=lpBits;
dlg.nWidth=nWidth;
dlg.nHeight=nHeight;
dlg.DoModal();
if (dlg.Performed) NoColor();
}
void CCarLPDlg::Scan()
{
/*CScanner dlg;
if (dlg.DoModal()==IDOK)
{
ShellExecute(m_hWnd,"open",dlg.scanner,0,dlg.scanner_path,SW_SHOW);
}*/
}
//CCPEControl cpe;
//DEL void CDIPDemoDlg::Grab()
//DEL {
//DEL // TODO: Add your command handler code here
//DEL if (cpe.InitCPE(source.m_hWnd)==-1) return;
//DEL cpe.RTDisplay();
//DEL Grabbing=TRUE;
//DEL // CRect rect;
//DEL // GetParent()->GetClientRect(rect);
//DEL // SetScrollSizes(MM_TEXT,CSize(rect.right,rect.bottom));
//DEL if (lpBitmap)
//DEL {
//DEL delete lpBitmap;
//DEL lpBitmap=0;
//DEL }
//DEL }
//DEL void CDIPDemoDlg::Snap()
//DEL {
//DEL // TODO: Add your command handler code here
//DEL cpe.RTStop();
//DEL nWidth=cpe.m_GrabWndWidth;
//DEL nWidth/=4;
//DEL nWidth*=4;
//DEL nHeight=cpe.m_GrabWndHeight;
//DEL nHeight/=2;
//DEL nHeight*=2;
//DEL nByteWidth=nWidth*3;
//DEL if (nByteWidth%4) nByteWidth+=4-(nByteWidth%4);
//DEL nLen=nByteWidth*nHeight+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
//DEL lpBitmap=new BYTE[nLen];
//DEL
//DEL lpBits=lpBitmap+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
//DEL ZeroMemory(lpBitmap,nLen);
//DEL BITMAPFILEHEADER bmh;
//DEL BITMAPINFOHEADER bmi;
//DEL bmh.bfType='B'+'M'*256;
//DEL bmh.bfSize=nLen;
//DEL bmh.bfReserved1=0;
//DEL bmh.bfReserved2=0;
//DEL bmh.bfOffBits=54;
//DEL
//DEL bmi.biSize=sizeof(BITMAPINFOHEADER);
//DEL bmi.biWidth=nWidth;
//DEL bmi.biHeight=nHeight;
//DEL bmi.biPlanes=1;
//DEL bmi.biBitCount=24;
//DEL bmi.biCompression=BI_RGB;
//DEL bmi.biSizeImage=0;
//DEL bmi.biXPelsPerMeter=0;
//DEL bmi.biYPelsPerMeter=0;
//DEL bmi.biClrUsed=0;
//DEL bmi.biClrImportant=0;
//DEL memcpy(lpBitmap,&bmh,sizeof(BITMAPFILEHEADER));
//DEL memcpy(lpBitmap+sizeof(BITMAPFILEHEADER),&bmi,sizeof(BITMAPINFOHEADER));
//DEL
//DEL memcpy(lpBits,cpe.lpDib,nByteWidth*nHeight);
//DEL
//DEL // MessageBox("Step 3 ok");
//DEL cpe.CPEExit();
//DEL Grabbing=FALSE;
//DEL source.SetImage(nWidth,nHeight,lpBits);
//DEL }
void CCarLPDlg::OnOK()
{
// TODO: Add extra validation here
// CDialog::OnOK();
}
void CCarLPDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CCarLPDlg::WinHelp(DWORD dwData, UINT nCmd)
{
// TODO: Add your specialized code here and/or call the base class
CHelpDlg dlg;
dlg.DoModal();
}
bool HoughTF(long lWidth,long lHeight,BYTE *lpInput,BYTE *lpOutput);
bool NoiseRm(int lWidth,int lHeight,BYTE *lpOutput);
void BiValue3(int nWidth,int nHeight,BYTE *lpInput,BYTE *lpOutput);
void CCarLPDlg::HoughIMG()
{
if (lpBitmap==0) return ;
BYTE *lpOutput=new BYTE[nByteWidth*nHeight];
BiValue3(nWidth,nHeight,lpBits,lpOutput);
//memcpy(lpOutput,lpBits,nByteWidth*nHeight);
//NoiseRm(nWidth,nHeight,lpOutput);
dest.SetImage(nWidth,nHeight,lpOutput);
delete lpOutput;
//return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -