📄 shiyuview.cpp
字号:
pDoc->UpdateAllViews(NULL);
::GlobalUnlock((HGLOBAL)pDoc->GetHDIB());
EndWaitCursor();
}
void CShiyuView::OnMenuitemVertical()
{
// TODO: Add your command handler code here
CShiyuDoc* pDoc=GetDocument();
if(pDoc->m_hDIB==NULL)
{
MessageBox("请先打开一幅256色的BMP图像!","系统提示",MB_ICONINFORMATION|MB_OK);
return;
}
LPSTR lpDIB;
LPSTR lpDIBBits;
lpDIB=(LPSTR)::GlobalLock((HGLOBAL)pDoc->GetHDIB());
lpDIBBits=::FindDIBBits(lpDIB);
if(::DIBNumColors(lpDIB)!=256)
{
MessageBox("目前只支持256色位图!","系统提示",MB_ICONINFORMATION|MB_OK);
::GlobalUnlock((HGLOBAL)pDoc->GetHDIB());
return;
}
BeginWaitCursor();
::Vertical(lpDIBBits,::DIBWidth(lpDIB),::DIBHeight(lpDIB));
pDoc->SetModifiedFlag(TRUE);
pDoc->UpdateAllViews(NULL);
::GlobalUnlock((HGLOBAL)pDoc->GetHDIB());
EndWaitCursor();
}
void CShiyuView::OnMenuitemCircumrotate()
{
// TODO: Add your command handler code here
CShiyuDoc* pDoc=GetDocument();
if(pDoc->m_hDIB==NULL)
{
MessageBox("请先打开一幅256色的BMP图像!","系统提示",MB_ICONINFORMATION|MB_OK);
return;
}
LPSTR lpDIB;
LPSTR lpDIBBits;
lpDIB=(LPSTR)::GlobalLock((HGLOBAL)pDoc->GetHDIB());
lpDIBBits=::FindDIBBits(lpDIB);
if(::DIBNumColors(lpDIB)!=256)
{
MessageBox("目前只支持256色位图!","系统提示",MB_ICONINFORMATION|MB_OK);
::GlobalUnlock((HGLOBAL)pDoc->GetHDIB());
return;
}
BeginWaitCursor();
::Circumrotate(lpDIBBits,::DIBWidth(lpDIB),::DIBHeight(lpDIB));
pDoc->SetModifiedFlag(TRUE);
pDoc->UpdateAllViews(NULL);
::GlobalUnlock((HGLOBAL)pDoc->GetHDIB());
EndWaitCursor();
}
void CShiyuView::OnMenuitemLinetrans()
{
// TODO: Add your command handler code here
CShiyuDoc* pDoc=GetDocument();
if(pDoc->m_hDIB==NULL)
{
MessageBox("请先打开一幅256色的BMP图像!","系统提示",MB_ICONINFORMATION|MB_OK);
return;
}
LPSTR lpDIB;
LPSTR lpDIBBits;
int X1,X2,Y1,Y2;
lpDIB=(LPSTR)::GlobalLock((HGLOBAL)pDoc->GetHDIB());
lpDIBBits=::FindDIBBits(lpDIB);
if(::DIBNumColors(lpDIB)!=256)
{
MessageBox("目前只支持256色位图!","系统提示",MB_ICONINFORMATION|MB_OK);
::GlobalUnlock((HGLOBAL)pDoc->GetHDIB());
return;
}
clinetrans dlgParam;
if(dlgParam.DoModal()!=IDOK)
{
return;
}
X1=dlgParam.m_x1;
X2=dlgParam.m_x2;
Y1=dlgParam.m_y1;
Y2=dlgParam.m_y2;
delete dlgParam;
BeginWaitCursor();
::LinerTrans(lpDIBBits,::DIBWidth(lpDIB),::DIBHeight(lpDIB),X1,Y1,X2,Y2);
pDoc->SetModifiedFlag(TRUE);
pDoc->UpdateAllViews(NULL);
::GlobalUnlock((HGLOBAL)pDoc->GetHDIB());
EndWaitCursor();
}
void CShiyuView::OnMenuitemChangsize()
{
// TODO: Add your command handler code here
CShiyuDoc* pDoc = GetDocument();
////////////////////////////////////////////////////////////////////////////////////////////////
long lSrcLineBytes; //图象每行的字节数
long lSrcWidth; //图象的宽度和高度
long lSrcHeight;
LPSTR lpSrcDib; //指向源图象的指针
LPSTR lpSrcStartBits; //指向源像素的指针
long lDstWidth; //临时图象的宽度和高度
long lDstHeight;
long lDstLineBytes;
lpSrcDib=(LPSTR)::GlobalLock((HGLOBAL)pDoc->GetHDIB());// 锁定DIB
if (::DIBNumColors(lpSrcDib)!=256)// 判断是否是8-bpp位图
{
AfxMessageBox("对不起,不是256色位图!");// 警告
::GlobalUnlock((HGLOBAL) pDoc->GetHDIB());// 解除锁定
return; //返回
}
// lpSrcStartBits=pDoc->m_dib.GetBits(lpSrcDib);// 找到DIB图象像素起始位置
lpSrcStartBits=lpSrcDib + ((LPBITMAPINFOHEADER)lpSrcDib)->biSize+(WORD)(256 * sizeof(RGBQUAD));//(WORD)(GetColorNum(lpSrcDib) * sizeof(RGBQUAD))
lSrcWidth= (int)::DIBWidth(lpSrcDib); // 获取图象的宽度
lSrcHeight= (int)::DIBWidth(lpSrcDib); // 获取图象的高度
lSrcLineBytes=WIDTHBYTES(lSrcWidth * 8); // 计算图象每行的字节数
/////////////////////////////////////////////////////////////////////////////////////////////////
DWORD palSize=(WORD)(256 * sizeof(RGBQUAD));
CsizeChange ZoomPara;// 创建对话框,设定平移量
if (ZoomPara.DoModal() != IDOK)
{
return;
}
float fX = ZoomPara.m_horZoom;// 获取设定的平移量,缩放比率
float fY = ZoomPara.m_verZoom;
lDstWidth= (long) (lSrcWidth*fX + 0.5);// 计算缩放后的图象实际宽度,加0.5是由于强制类型转换时不四舍五入,而是直接截去小数部分
lDstLineBytes=WIDTHBYTES(lDstWidth * 8); //转换后图象应有的行字节数,为4的倍数
lDstHeight= (long) (lSrcHeight * fY + 0.5);// 计算缩放后的图象高度
HGLOBAL hDstDIB = NULL;// 创建新DIB
hDstDIB = (HGLOBAL) Zoom(lpSrcDib,lpSrcStartBits,lSrcWidth,lSrcHeight,
lSrcLineBytes,palSize,lDstWidth,lDstLineBytes,lDstHeight,fX, fY);// 调用Zoom()函数转置DIB
if(hDstDIB != NULL)// 判断旋转是否成功
{
pDoc->ReplaceHDIB(HDIB(hDstDIB));// 替换DIB,同时释放旧DIB对象
pDoc->SetDib();// 更新DIB大小和调色板
pDoc->SetModifiedFlag(TRUE); // 设置脏标记
pDoc->UpdateAllViews(NULL); // 更新视图
::GlobalUnlock((HGLOBAL) pDoc->GetHDIB()); // 解除锁定
}
else
{
AfxMessageBox(_T("分配内存失败!"));
}
// 警告
}
void CShiyuView::OnMenuitemMidfilter()
{
// TODO: Add your command handler code here
CShiyuDoc* pDoc=GetDocument();
if(pDoc->m_hDIB==NULL)
{
MessageBox("请先打开一幅256色的BMP图像!","系统提示",MB_ICONINFORMATION|MB_OK);
return;
}
LPSTR lpDIB;
LPSTR lpDIBBits;
lpDIB=(LPSTR)::GlobalLock((HGLOBAL)pDoc->GetHDIB());
lpDIBBits=::FindDIBBits(lpDIB);
if(::DIBNumColors(lpDIB)!=256)
{
MessageBox("目前只支持256色位图!","系统提示",MB_ICONINFORMATION|MB_OK);
::GlobalUnlock((HGLOBAL)pDoc->GetHDIB());
return;
}
BeginWaitCursor();
::MidFilter(lpDIBBits,::DIBWidth(lpDIB),::DIBHeight(lpDIB));
pDoc->SetModifiedFlag(TRUE);
pDoc->UpdateAllViews(NULL);
::GlobalUnlock((HGLOBAL)pDoc->GetHDIB());
EndWaitCursor();
}
void CShiyuView::OnMenuitemSobel()
{
// TODO: Add your command handler code here
/*
HANDLE data1handle;
LPBITMAPINFOHEADER lpBi;
CDibDoc *pDoc=GetDocument();
HDIB hdib;
//unsigned char *hData;
LPSTR hData;
//unsigned char *data;
LPSTR data;
hdib=pDoc->m_hDIB;
//hData=(LPSTR)::GlobalLock((HGLOBAL)pDoc->GetHDIB())
BeginWaitCursor();
lpBi=(LPBITMAPINFOHEADER)GlobalLock((HGLOBAL)hdib);
hData= lpbi +* (LPDWORD)lpbi + 256*sizeof(RGBQUAD);
//得到指向位图像素值的指针
pDoc->SetModifiedFlag(TRUE);//设修改标志为"TRUE"
data1handle=GlobalAlloc(GMEM_SHARE,WIDTHBYTES(lpBi->biWidth*8)*lpBi->biHeight);
//申请存放处理后的像素值的缓冲区
data=(unsigned char*)GlobalLock((HGLOBAL)data1handle);
AfxGetApp()->BeginWaitCursor();
int i,j,buf,buf1,buf2;
for( j=0; j<biHeight; j++)//以下循环求(x,y)位置的灰度值
for( i=0; i<biWidth; i++)
{
if(((i-1)>=0)&&((i+1)biWidth)&&((j-1)>=0)&&((j+1)biHeight))
{//对于图像四周边界处的向素点不处理
buf1=(int)*(hData+(i+1)*WIDTHBYTES(lpBi->biWidth*8)+(j-1))
+2*(int)*(hData+(i+1)*WIDTHBYTES(lpBi->biWidth*8)+(j))
+(int)(int)*(hData+(i+1)*WIDTHBYTES(lpBi->biWidth*8)+(j+1));
buf1=buf1-(int)(int)*(hData+(i-1)*WIDTHBYTES(lpBi->biWidth*8)+(j-1))
-2*(int)(int)*(hData+(i-1)*WIDTHBYTES(lpBi->biWidth*8)+(j))
-(int)(int)*(hData+(i-1)*WIDTHBYTES(lpBi->biWidth*8)+(j+1));
//x方向加权微分
buf2=(int)(int)*(hData+(i-1)*WIDTHBYTES(lpBi->biWidth*8)+(j+1))
+2*(int)(int)*(hData+(i)*WIDTHBYTES(lpBi->biWidth*8)+(j+1))
+(int)(int)*(hData+(i+1)*WIDTHBYTES(lpBi->biWidth*8)+(j+1));
buf2=buf2-(int)(int)*(hData+(i-1)*WIDTHBYTES(lpBi->biWidth*8)+(j-1))
-2*(int)(int)*(hData+(i)*WIDTHBYTES(lpBi->biWidth*8)+(j-1))
-(int)(int)*(hData+(i+1)*WIDTHBYTES(lpBi->biWidth*8)+(j-1));
//y方向加权微分
buf=abs(buf1)+abs(buf2);//求梯度
if(buf>255) buf=255;
if(buf<0){buf=0;
*(data+i*WIDTHBYTES(lpBi->biWidth*8)+j)=(BYTE)buf;
}
else *(data+i*lpBi->biWidth+j)=(BYTE)0;
}
for( j=0; jbiHeight; j++)
for( i=0; ibiWidth; i++)
*(hData+i*WIDTHBYTES(lpBi->biWidth*8)+j)=*(data+i*WIDTHBYTES(lpBi->biWidth*8)+j);
//处理后的数据写回原缓冲区
AfxGetApp()->EndWaitCursor();
GlobalUnlock((HGLOBAL)hdib);
GlobalUnlock(data1handle);
GlobalFree(date1handle);
EndWaitCursor();
Invalidate(TRUE);
*/
CShiyuDoc* pDoc=GetDocument();
if(pDoc->m_hDIB==NULL)
{
MessageBox("请先打开一幅256色的BMP图像!","系统提示",MB_ICONINFORMATION|MB_OK);
return;
}
LPSTR lpDIB;
LPSTR lpDIBBits;
lpDIB=(LPSTR)::GlobalLock((HGLOBAL)pDoc->GetHDIB());
lpDIBBits=::FindDIBBits(lpDIB);
if(::DIBNumColors(lpDIB)!=256)
{
MessageBox("目前只支持256色位图!","系统提示",MB_ICONINFORMATION|MB_OK);
::GlobalUnlock((HGLOBAL)pDoc->GetHDIB());
return;
}
BeginWaitCursor();
::Sobel(lpDIBBits,::DIBWidth(lpDIB),::DIBHeight(lpDIB));
pDoc->SetModifiedFlag(TRUE);
pDoc->UpdateAllViews(NULL);
::GlobalUnlock((HGLOBAL)pDoc->GetHDIB());
EndWaitCursor();
}
void CShiyuView::OnMenuitemRoberts()
{
// TODO: Add your command handler code here
CShiyuDoc* pDoc=GetDocument();
if(pDoc->m_hDIB==NULL)
{
MessageBox("请先打开一幅256色的BMP图像!","系统提示",MB_ICONINFORMATION|MB_OK);
return;
}
LPSTR lpDIB;
LPSTR lpDIBBits;
lpDIB=(LPSTR)::GlobalLock((HGLOBAL)pDoc->GetHDIB());
lpDIBBits=::FindDIBBits(lpDIB);
if(::DIBNumColors(lpDIB)!=256)
{
MessageBox("目前只支持256色位图!","系统提示",MB_ICONINFORMATION|MB_OK);
::GlobalUnlock((HGLOBAL)pDoc->GetHDIB());
return;
}
BeginWaitCursor();
::Roberts(lpDIBBits,::DIBWidth(lpDIB),::DIBHeight(lpDIB));
pDoc->SetModifiedFlag(TRUE);
pDoc->UpdateAllViews(NULL);
::GlobalUnlock((HGLOBAL)pDoc->GetHDIB());
EndWaitCursor();
}
void CShiyuView::OnMenuitemPrewitt()
{
// TODO: Add your command handler code here
CShiyuDoc* pDoc=GetDocument();
if(pDoc->m_hDIB==NULL)
{
MessageBox("请先打开一幅256色的BMP图像!","系统提示",MB_ICONINFORMATION|MB_OK);
return;
}
LPSTR lpDIB;
LPSTR lpDIBBits;
lpDIB=(LPSTR)::GlobalLock((HGLOBAL)pDoc->GetHDIB());
lpDIBBits=::FindDIBBits(lpDIB);
if(::DIBNumColors(lpDIB)!=256)
{
MessageBox("目前只支持256色位图!","系统提示",MB_ICONINFORMATION|MB_OK);
::GlobalUnlock((HGLOBAL)pDoc->GetHDIB());
return;
}
BeginWaitCursor();
::Prewitt(lpDIBBits,::DIBWidth(lpDIB),::DIBHeight(lpDIB));
pDoc->SetModifiedFlag(TRUE);
pDoc->UpdateAllViews(NULL);
::GlobalUnlock((HGLOBAL)pDoc->GetHDIB());
EndWaitCursor();
}
void CShiyuView::OnMenuitemLaplacian()
{
// TODO: Add your command handler code here
CShiyuDoc* pDoc=GetDocument();
if(pDoc->m_hDIB==NULL)
{
MessageBox("请先打开一幅256色的BMP图像!","系统提示",MB_ICONINFORMATION|MB_OK);
return;
}
LPSTR lpDIB;
LPSTR lpDIBBits;
lpDIB=(LPSTR)::GlobalLock((HGLOBAL)pDoc->GetHDIB());
lpDIBBits=::FindDIBBits(lpDIB);
if(::DIBNumColors(lpDIB)!=256)
{
MessageBox("目前只支持256色位图!","系统提示",MB_ICONINFORMATION|MB_OK);
::GlobalUnlock((HGLOBAL)pDoc->GetHDIB());
return;
}
BeginWaitCursor();
::Laplacian(lpDIBBits,::DIBWidth(lpDIB),::DIBHeight(lpDIB));
pDoc->SetModifiedFlag(TRUE);
pDoc->UpdateAllViews(NULL);
::GlobalUnlock((HGLOBAL)pDoc->GetHDIB());
EndWaitCursor();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -